| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 | <h1>docker swarm init</h1>  <p><br></p> <p>Initialize a swarm</p> <p><span class="badge badge-info" data-toggle="tooltip" data-placement="right" title="This command works with the Swarm orchestrator.">Swarm</span> This command works with the Swarm orchestrator.</p> <h2 id="usage">Usage</h2> <div class="highlight"><pre class="highlight" data-language="">$ docker swarm init [OPTIONS]
</pre></div> <p>Refer to the <a href="#options">options section</a> for an overview of available <a href="#options"><code class="language-plaintext highlighter-rouge">OPTIONS</code></a> for this command.</p> <h2 id="description">Description</h2> <p name="extended-description">Initialize a swarm. The docker engine targeted by this command becomes a manager in the newly created single-node swarm.</p> <p>For example uses of this command, refer to the <a href="#examples">examples section</a> below.</p> <h2 id="options">Options</h2> <table> <thead> <tr> <td>Name, shorthand</td> <td>Default</td> <td>Description</td> </tr> </thead> <tbody> <tr> <td><code class="language-plaintext highlighter-rouge">--advertise-addr</code></td> <td></td> <td>Advertised address (format: <ip|interface>[:port])</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--autolock</code></td> <td></td> <td>Enable manager autolocking (requiring an unlock key to start a stopped manager)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--availability</code></td> <td><code class="language-plaintext highlighter-rouge">active</code></td> <td>Availability of the node ("active"|"pause"|"drain")</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--cert-expiry</code></td> <td><code class="language-plaintext highlighter-rouge">2160h0m0s</code></td> <td>Validity period for node certificates (ns|us|ms|s|m|h)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--data-path-addr</code></td> <td></td> <td>Address or interface to use for data path traffic (format: <ip|interface>)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--data-path-port</code></td> <td></td> <td>
<a href="https://docs.docker.com/engine/api/v1.40/" target="_blank" rel="noopener" class="_"><span class="badge badge-info" data-toggle="tooltip" title="Open the 1.24 API reference (in a new window)">API 1.40+</span></a><br>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.</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--default-addr-pool</code></td> <td></td> <td>
<a href="https://docs.docker.com/engine/api/v1.40/" target="_blank" rel="noopener" class="_"><span class="badge badge-info" data-toggle="tooltip" title="Open the 1.24 API reference (in a new window)">API 1.40+</span></a><br>default address pool in CIDR format</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--default-addr-pool-mask-length</code></td> <td><code class="language-plaintext highlighter-rouge">24</code></td> <td>
<a href="https://docs.docker.com/engine/api/v1.40/" target="_blank" rel="noopener" class="_"><span class="badge badge-info" data-toggle="tooltip" title="Open the 1.24 API reference (in a new window)">API 1.40+</span></a><br>default address pool subnet mask length</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--dispatcher-heartbeat</code></td> <td><code class="language-plaintext highlighter-rouge">5s</code></td> <td>Dispatcher heartbeat period (ns|us|ms|s|m|h)</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--external-ca</code></td> <td></td> <td>Specifications of one or more certificate signing endpoints</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--force-new-cluster</code></td> <td></td> <td>Force create a new cluster from current state</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--listen-addr</code></td> <td><code class="language-plaintext highlighter-rouge">0.0.0.0:2377</code></td> <td>Listen address (format: <ip|interface>[:port])</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--max-snapshots</code></td> <td></td> <td>Number of additional Raft snapshots to retain</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--snapshot-interval</code></td> <td><code class="language-plaintext highlighter-rouge">10000</code></td> <td>Number of log entries between Raft snapshots</td> </tr> <tr> <td><code class="language-plaintext highlighter-rouge">--task-history-limit</code></td> <td><code class="language-plaintext highlighter-rouge">5</code></td> <td>Task history retention limit</td> </tr>  </tbody> </table>  <h2 id="examples">Examples</h2> <div class="highlight"><pre class="highlight" data-language="">$ docker swarm init --advertise-addr 192.168.99.121
Swarm initialized: current node (bvz81updecsj6wjz393c09vti) is now a manager.
To add a worker to this swarm, run the following command:
    docker swarm join \
    --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx \
    172.17.0.2:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
</pre></div> <p><code class="language-plaintext highlighter-rouge">docker swarm init</code> generates two random tokens, a worker token and a manager token. When you join a new node to the swarm, the node joins as a worker or manager node based upon the token you pass to <a href="../swarm_join/index">swarm join</a>.</p> <p>After you create the swarm, you can display or rotate the token using <a href="../swarm_join-token/index">swarm join-token</a>.</p> <h3 id="--autolock"><code class="language-plaintext highlighter-rouge">--autolock</code></h3> <p>This flag enables automatic locking of managers with an encryption key. The private keys and data stored by all managers will be protected by the encryption key printed in the output, and will not be accessible without it. Thus, it is very important to store this key in order to activate a manager after it restarts. The key can be passed to <code class="language-plaintext highlighter-rouge">docker swarm unlock</code> to reactivate the manager. Autolock can be disabled by running <code class="language-plaintext highlighter-rouge">docker swarm update --autolock=false</code>. After disabling it, the encryption key is no longer required to start the manager, and it will start up on its own without user intervention.</p> <h3 id="--cert-expiry"><code class="language-plaintext highlighter-rouge">--cert-expiry</code></h3> <p>This flag sets the validity period for node certificates.</p> <h3 id="--dispatcher-heartbeat"><code class="language-plaintext highlighter-rouge">--dispatcher-heartbeat</code></h3> <p>This flag sets the frequency with which nodes are told to use as a period to report their health.</p> <h3 id="--external-ca"><code class="language-plaintext highlighter-rouge">--external-ca</code></h3> <p>This flag sets up the swarm to use an external CA to issue node certificates. The value takes the form <code class="language-plaintext highlighter-rouge">protocol=X,url=Y</code>. The value for <code class="language-plaintext highlighter-rouge">protocol</code> specifies what protocol should be used to send signing requests to the external CA. Currently, the only supported value is <code class="language-plaintext highlighter-rouge">cfssl</code>. The URL specifies the endpoint where signing requests should be submitted.</p> <h3 id="--force-new-cluster"><code class="language-plaintext highlighter-rouge">--force-new-cluster</code></h3> <p>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.</p> <h3 id="--listen-addr"><code class="language-plaintext highlighter-rouge">--listen-addr</code></h3> <p>The node listens for inbound swarm manager traffic on this address. The default is to listen on 0.0.0.0:2377. It is also possible to specify a network interface to listen on that interface’s address; for example <code class="language-plaintext highlighter-rouge">--listen-addr eth0:2377</code>.</p> <p>Specifying a port is optional. If the value is a bare IP address or interface name, the default port 2377 will be used.</p> <h3 id="--advertise-addr"><code class="language-plaintext highlighter-rouge">--advertise-addr</code></h3> <p>This flag specifies the address that will be advertised to other members of the swarm for API access and overlay networking. If unspecified, Docker will check if the system has a single IP address, and use that IP address with the listening port (see <code class="language-plaintext highlighter-rouge">--listen-addr</code>). If the system has multiple IP addresses, <code class="language-plaintext highlighter-rouge">--advertise-addr</code> must be specified so that the correct address is chosen for inter-manager communication and overlay networking.</p> <p>It is also possible to specify a network interface to advertise that interface’s address; for example <code class="language-plaintext highlighter-rouge">--advertise-addr eth0:2377</code>.</p> <p>Specifying a port is optional. If the value is a bare IP address or interface name, the default port 2377 will be used.</p> <h3 id="--data-path-addr"><code class="language-plaintext highlighter-rouge">--data-path-addr</code></h3> <p>This flag specifies the address that global scope network drivers will publish towards other nodes in order to reach the containers running on this node. Using this parameter it is then possible to separate the container’s data traffic from the management traffic of the cluster. If unspecified, Docker will use the same IP address or interface that is used for the advertise address.</p> <h3 id="--data-path-port"><code class="language-plaintext highlighter-rouge">--data-path-port</code></h3> <p>This flag allows you to configure the UDP port number to use for data path traffic. The provided port number must be within the 1024 - 49151 range. If this flag is not set or is set to 0, the default port number 4789 is used. The data path port can only be configured when initializing the swarm, and applies to all nodes that join the swarm. The following example initializes a new Swarm, and configures the data path port to UDP port 7777;</p> <div class="highlight"><pre class="highlight" data-language="">$ docker swarm init --data-path-port=7777
</pre></div> <p>After the swarm is initialized, use the <code class="language-plaintext highlighter-rouge">docker info</code> command to verify that the port is configured:</p> <div class="highlight"><pre class="highlight" data-language="">$ docker info
<...>
ClusterID: 9vs5ygs0gguyyec4iqf2314c0
Managers: 1
Nodes: 1
Data Path Port: 7777
<...>
</pre></div> <h3 id="--default-addr-pool"><code class="language-plaintext highlighter-rouge">--default-addr-pool</code></h3> <p>This flag specifies default subnet pools for global scope networks. Format example is <code class="language-plaintext highlighter-rouge">--default-addr-pool 30.30.0.0/16 --default-addr-pool 40.40.0.0/16</code></p> <h3 id="--default-addr-pool-mask-length"><code class="language-plaintext highlighter-rouge">--default-addr-pool-mask-length</code></h3> <p>This flag specifies default subnet pools mask length for default-addr-pool. Format example is <code class="language-plaintext highlighter-rouge">--default-addr-pool-mask-length 24</code></p> <h3 id="--task-history-limit"><code class="language-plaintext highlighter-rouge">--task-history-limit</code></h3> <p>This flag sets up task history retention limit.</p> <h3 id="--max-snapshots"><code class="language-plaintext highlighter-rouge">--max-snapshots</code></h3> <p>This flag sets the number of old Raft snapshots to retain in addition to the current Raft snapshots. By default, no old snapshots are retained. This option may be used for debugging, or to store old snapshots of the swarm state for disaster recovery purposes.</p> <h3 id="--snapshot-interval"><code class="language-plaintext highlighter-rouge">--snapshot-interval</code></h3> <p>This flag specifies how many log entries to allow in between Raft snapshots. Setting this to a higher number will trigger snapshots less frequently. Snapshots compact the Raft log and allow for more efficient transfer of the state to new managers. However, there is a performance cost to taking snapshots frequently.</p> <h3 id="--availability"><code class="language-plaintext highlighter-rouge">--availability</code></h3> <p>This flag specifies the availability of the node at the time the node joins a master. Possible availability values are <code class="language-plaintext highlighter-rouge">active</code>, <code class="language-plaintext highlighter-rouge">pause</code>, or <code class="language-plaintext highlighter-rouge">drain</code>.</p> <p>This flag is useful in certain situations. For example, a cluster may want to have dedicated manager nodes that are not served as worker nodes. This could be achieved by passing <code class="language-plaintext highlighter-rouge">--availability=drain</code> to <code class="language-plaintext highlighter-rouge">docker swarm init</code>.</p> <h2 id="parent-command">Parent command</h2> <table> <thead> <tr> <th style="text-align: left">Command</th> <th style="text-align: left">Description</th> </tr> </thead> <tbody> <tr> <td style="text-align: left"><a href="../swarm/index">docker swarm</a></td> <td style="text-align: left">Manage Swarm</td> </tr> </tbody> </table> <h2 id="related-commands">Related commands</h2> <table> <thead> <tr> <td>Command</td> <td>Description</td> </tr> </thead> <tbody> <tr> <td><a href="../swarm_ca/index">docker swarm ca</a></td> <td>Display and rotate the root CA</td> </tr> <tr> <td><a href="index">docker swarm init</a></td> <td>Initialize a swarm</td> </tr> <tr> <td><a href="../swarm_join/index">docker swarm join</a></td> <td>Join a swarm as a node and/or manager</td> </tr> <tr> <td><a href="../swarm_join-token/index">docker swarm join-token</a></td> <td>Manage join tokens</td> </tr> <tr> <td><a href="../swarm_leave/index">docker swarm leave</a></td> <td>Leave the swarm</td> </tr> <tr> <td><a href="../swarm_unlock/index">docker swarm unlock</a></td> <td>Unlock swarm</td> </tr> <tr> <td><a href="../swarm_unlock-key/index">docker swarm unlock-key</a></td> <td>Manage the unlock key</td> </tr> <tr> <td><a href="../swarm_update/index">docker swarm update</a></td> <td>Update the swarm</td> </tr> </tbody> </table> <div class="_attribution">
  <p class="_attribution-p">
    © 2019 Docker, Inc.<br>Licensed under the Apache License, Version 2.0.<br>Docker and the Docker logo are trademarks or registered trademarks of Docker, Inc. in the United States and/or other countries.<br>Docker, Inc. and other parties may also have trademark rights in other terms used herein.<br>
    <a href="https://docs.docker.com/engine/reference/commandline/swarm_init/" class="_attribution-link">https://docs.docker.com/engine/reference/commandline/swarm_init/</a>
  </p>
</div>
 |