github.com/sld880311/docker@v0.0.0-20200524143708-d5593973a475/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/docker Github 8 repository at https://github.com/docker/docker/. 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 --cert-expiry duration Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s) 27 --dispatcher-heartbeat duration Dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s) 28 --external-ca external-ca Specifications of one or more certificate signing endpoints 29 --force-new-cluster Force create a new cluster from current state 30 --help Print usage 31 --listen-addr node-addr Listen address (format: <ip|interface>[:port]) (default 0.0.0.0:2377) 32 --max-snapshots uint Number of additional Raft snapshots to retain 33 --snapshot-interval uint Number of log entries between Raft snapshots (default 10000) 34 --task-history-limit int Task history retention limit (default 5) 35 ``` 36 37 ## Description 38 39 Initialize a swarm. The docker engine targeted by this command becomes a manager 40 in the newly created single-node swarm. 41 42 ## Examples 43 44 ```bash 45 $ docker swarm init --advertise-addr 192.168.99.121 46 Swarm initialized: current node (bvz81updecsj6wjz393c09vti) is now a manager. 47 48 To add a worker to this swarm, run the following command: 49 50 docker swarm join \ 51 --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx \ 52 172.17.0.2:2377 53 54 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions. 55 ``` 56 57 `docker swarm init` generates two random tokens, a worker token and a manager token. When you join 58 a new node to the swarm, the node joins as a worker or manager node based upon the token you pass 59 to [swarm join](swarm_join.md). 60 61 After you create the swarm, you can display or rotate the token using 62 [swarm join-token](swarm_join_token.md). 63 64 ### `--autolock` 65 66 This flag enables automatic locking of managers with an encryption key. The 67 private keys and data stored by all managers will be protected by the 68 encryption key printed in the output, and will not be accessible without it. 69 Thus, it is very important to store this key in order to activate a manager 70 after it restarts. The key can be passed to `docker swarm unlock` to reactivate 71 the manager. Autolock can be disabled by running 72 `docker swarm update --autolock=false`. After disabling it, the encryption key 73 is no longer required to start the manager, and it will start up on its own 74 without user intervention. 75 76 ### `--cert-expiry` 77 78 This flag sets the validity period for node certificates. 79 80 ### `--dispatcher-heartbeat` 81 82 This flag sets the frequency with which nodes are told to use as a 83 period to report their health. 84 85 ### `--external-ca` 86 87 This flag sets up the swarm to use an external CA to issue node certificates. The value takes 88 the form `protocol=X,url=Y`. The value for `protocol` specifies what protocol should be used 89 to send signing requests to the external CA. Currently, the only supported value is `cfssl`. 90 The URL specifies the endpoint where signing requests should be submitted. 91 92 ### `--force-new-cluster` 93 94 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. 95 96 ### `--listen-addr` 97 98 The node listens for inbound swarm manager traffic on this address. The default is to listen on 99 0.0.0.0:2377. It is also possible to specify a network interface to listen on that interface's 100 address; for example `--listen-addr eth0:2377`. 101 102 Specifying a port is optional. If the value is a bare IP address or interface 103 name, the default port 2377 will be used. 104 105 ### `--advertise-addr` 106 107 This flag specifies the address that will be advertised to other members of the 108 swarm for API access and overlay networking. If unspecified, Docker will check 109 if the system has a single IP address, and use that IP address with the 110 listening port (see `--listen-addr`). If the system has multiple IP addresses, 111 `--advertise-addr` must be specified so that the correct address is chosen for 112 inter-manager communication and overlay networking. 113 114 It is also possible to specify a network interface to advertise that interface's address; 115 for example `--advertise-addr eth0:2377`. 116 117 Specifying a port is optional. If the value is a bare IP address or interface 118 name, the default port 2377 will be used. 119 120 ### `--task-history-limit` 121 122 This flag sets up task history retention limit. 123 124 ### `--max-snapshots` 125 126 This flag sets the number of old Raft snapshots to retain in addition to the 127 current Raft snapshots. By default, no old snapshots are retained. This option 128 may be used for debugging, or to store old snapshots of the swarm state for 129 disaster recovery purposes. 130 131 ### `--snapshot-interval` 132 133 This flag specifies how many log entries to allow in between Raft snapshots. 134 Setting this to a higher number will trigger snapshots less frequently. 135 Snapshots compact the Raft log and allow for more efficient transfer of the 136 state to new managers. However, there is a performance cost to taking snapshots 137 frequently. 138 139 ## Related commands 140 141 * [swarm join](swarm_join.md) 142 * [swarm leave](swarm_leave.md) 143 * [swarm update](swarm_update.md) 144 * [swarm join-token](swarm_join_token.md) 145 * [node rm](node_rm.md)