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