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