github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/docs/reference/commandline/swarm_init.md (about)

     1  ---
     2  title: "swarm init"
     3  description: "The swarm init command description and usage"
     4  keywords: "swarm, init"
     5  ---
     6  
     7  <!-- This file is maintained within the docker/cli GitHub
     8       repository at https://github.com/docker/cli/. Make all
     9       pull requests against that repo. If you see this file in
    10       another repository, consider it read-only there, as it will
    11       periodically be overwritten by the definitive file. Pull
    12       requests which include edits to this file in other repositories
    13       will be rejected.
    14  -->
    15  
    16  # swarm init
    17  
    18  ```markdown
    19  Usage:  docker swarm init [OPTIONS]
    20  
    21  Initialize a swarm
    22  
    23  Options:
    24        --advertise-addr string           Advertised address (format: <ip|interface>[:port])
    25        --autolock                        Enable manager autolocking (requiring an unlock key to start a stopped manager)
    26        --availability string             Availability of the node ("active"|"pause"|"drain") (default "active")
    27        --cert-expiry duration            Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s)
    28        --data-path-addr string           Address or interface to use for data path traffic (format: <ip|interface>)
    29        --default-addr-pool IPnet         List of default address pool (format: <cidr>)
    30        --default-addr-pool-mask-length   Subnet mask length for default address pool (default 24)
    31        --dispatcher-heartbeat duration   Dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s)
    32        --external-ca external-ca         Specifications of one or more certificate signing endpoints
    33        --force-new-cluster               Force create a new cluster from current state
    34        --help                            Print usage
    35        --listen-addr node-addr           Listen address (format: <ip|interface>[:port]) (default 0.0.0.0:2377)
    36        --max-snapshots uint              Number of additional Raft snapshots to retain
    37        --snapshot-interval uint          Number of log entries between Raft snapshots (default 10000)
    38        --task-history-limit int          Task history retention limit (default 5)
    39  ```
    40  
    41  ## Description
    42  
    43  Initialize a swarm. The docker engine targeted by this command becomes a manager
    44  in the newly created single-node swarm.
    45  
    46  ## Examples
    47  
    48  ```bash
    49  $ docker swarm init --advertise-addr 192.168.99.121
    50  Swarm initialized: current node (bvz81updecsj6wjz393c09vti) is now a manager.
    51  
    52  To add a worker to this swarm, run the following command:
    53  
    54      docker swarm join \
    55      --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx \
    56      172.17.0.2:2377
    57  
    58  To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
    59  ```
    60  
    61  `docker swarm init` generates two random tokens, a worker token and a manager token. When you join
    62  a new node to the swarm, the node joins as a worker or manager node based upon the token you pass
    63  to [swarm join](swarm_join.md).
    64  
    65  After you create the swarm, you can display or rotate the token using
    66  [swarm join-token](swarm_join_token.md).
    67  
    68  ### `--autolock`
    69  
    70  This flag enables automatic locking of managers with an encryption key. The
    71  private keys and data stored by all managers will be protected by the
    72  encryption key printed in the output, and will not be accessible without it.
    73  Thus, it is very important to store this key in order to activate a manager
    74  after it restarts. The key can be passed to `docker swarm unlock` to reactivate
    75  the manager. Autolock can be disabled by running
    76  `docker swarm update --autolock=false`. After disabling it, the encryption key
    77  is no longer required to start the manager, and it will start up on its own
    78  without user intervention.
    79  
    80  ### `--cert-expiry`
    81  
    82  This flag sets the validity period for node certificates.
    83  
    84  ### `--dispatcher-heartbeat`
    85  
    86  This flag sets the frequency with which nodes are told to use as a
    87  period to report their health.
    88  
    89  ### `--external-ca`
    90  
    91  This flag sets up the swarm to use an external CA to issue node certificates. The value takes
    92  the form `protocol=X,url=Y`. The value for `protocol` specifies what protocol should be used
    93  to send signing requests to the external CA. Currently, the only supported value is `cfssl`.
    94  The URL specifies the endpoint where signing requests should be submitted.
    95  
    96  ### `--force-new-cluster`
    97  
    98  This flag forces an existing node that was part of a quorum that was lost to restart as a single node Manager without losing its data.
    99  
   100  ### `--listen-addr`
   101  
   102  The node listens for inbound swarm manager traffic on this address. The default is to listen on
   103  0.0.0.0:2377. It is also possible to specify a network interface to listen on that interface's
   104  address; for example `--listen-addr eth0:2377`.
   105  
   106  Specifying a port is optional. If the value is a bare IP address or interface
   107  name, the default port 2377 will be used.
   108  
   109  ### `--advertise-addr`
   110  
   111  This flag specifies the address that will be advertised to other members of the
   112  swarm for API access and overlay networking. If unspecified, Docker will check
   113  if the system has a single IP address, and use that IP address with the
   114  listening port (see `--listen-addr`). If the system has multiple IP addresses,
   115  `--advertise-addr` must be specified so that the correct address is chosen for
   116  inter-manager communication and overlay networking.
   117  
   118  It is also possible to specify a network interface to advertise that interface's address;
   119  for example `--advertise-addr eth0:2377`.
   120  
   121  Specifying a port is optional. If the value is a bare IP address or interface
   122  name, the default port 2377 will be used.
   123  
   124  ### `--data-path-addr`
   125  
   126  This flag specifies the address that global scope network drivers will publish towards
   127  other nodes in order to reach the containers running on this node.
   128  Using this parameter it is then possible to separate the container's data traffic from the
   129  management traffic of the cluster.
   130  If unspecified, Docker will use the same IP address or interface that is used for the
   131  advertise address.
   132  
   133  ### `--default-addr-pool`
   134  This flag specifies default subnet pools for global scope networks.
   135  Format example is `--default-addr-pool 30.30.0.0/16 --default-addr-pool 40.40.0.0/16`
   136  
   137  ### `--default-addr-pool-mask-length`
   138  This flag specifies default subnet pools mask length for default-addr-pool.
   139  Format example is `--default-addr-pool-mask-length 24`
   140  
   141  ### `--task-history-limit`
   142  
   143  This flag sets up task history retention limit.
   144  
   145  ### `--max-snapshots`
   146  
   147  This flag sets the number of old Raft snapshots to retain in addition to the
   148  current Raft snapshots. By default, no old snapshots are retained. This option
   149  may be used for debugging, or to store old snapshots of the swarm state for
   150  disaster recovery purposes.
   151  
   152  ### `--snapshot-interval`
   153  
   154  This flag specifies how many log entries to allow in between Raft snapshots.
   155  Setting this to a higher number will trigger snapshots less frequently.
   156  Snapshots compact the Raft log and allow for more efficient transfer of the
   157  state to new managers. However, there is a performance cost to taking snapshots
   158  frequently.
   159  
   160  ### `--availability`
   161  
   162  This flag specifies the availability of the node at the time the node joins a master.
   163  Possible availability values are `active`, `pause`, or `drain`.
   164  
   165  This flag is useful in certain situations. For example, a cluster may want to have
   166  dedicated manager nodes that are not served as worker nodes. This could be achieved
   167  by passing `--availability=drain` to `docker swarm init`.
   168  
   169  
   170  ## Related commands
   171  
   172  * [swarm ca](swarm_ca.md)
   173  * [swarm join](swarm_join.md)
   174  * [swarm join-token](swarm_join_token.md)
   175  * [swarm leave](swarm_leave.md)
   176  * [swarm unlock](swarm_unlock.md)
   177  * [swarm unlock-key](swarm_unlock_key.md)
   178  * [swarm update](swarm_update.md)