2016-10-14 18:30:36 -04:00
|
|
|
---
|
|
|
|
title: "swarm init"
|
|
|
|
description: "The swarm init command description and usage"
|
2016-11-03 18:48:30 -04:00
|
|
|
keywords: "swarm, init"
|
2016-10-14 18:30:36 -04:00
|
|
|
---
|
2016-06-13 22:57:19 -04:00
|
|
|
|
2016-10-19 13:25:45 -04:00
|
|
|
<!-- This file is maintained within the docker/docker Github
|
|
|
|
repository at https://github.com/docker/docker/. Make all
|
|
|
|
pull requests against that repo. If you see this file in
|
|
|
|
another repository, consider it read-only there, as it will
|
|
|
|
periodically be overwritten by the definitive file. Pull
|
|
|
|
requests which include edits to this file in other repositories
|
|
|
|
will be rejected.
|
|
|
|
-->
|
|
|
|
|
2016-06-13 22:57:19 -04:00
|
|
|
# swarm init
|
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
```markdown
|
|
|
|
Usage: docker swarm init [OPTIONS]
|
|
|
|
|
2016-07-20 14:15:08 -04:00
|
|
|
Initialize a swarm
|
2016-07-07 14:43:18 -04:00
|
|
|
|
|
|
|
Options:
|
2016-11-27 23:24:02 -05:00
|
|
|
--advertise-addr string Advertised address (format: <ip|interface>[:port])
|
2016-11-10 15:05:19 -05:00
|
|
|
--autolock Enable manager autolocking (requiring an unlock key to start a stopped manager)
|
2017-02-08 03:31:16 -05:00
|
|
|
--availability string Availability of the node ("active"|"pause"|"drain") (default "active")
|
2016-10-25 08:22:07 -04:00
|
|
|
--cert-expiry duration Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s)
|
2017-04-14 19:54:17 -04:00
|
|
|
--data-path-addr string Address or interface to use for data path traffic (format: <ip|interface>)
|
2016-10-25 08:22:07 -04:00
|
|
|
--dispatcher-heartbeat duration Dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s)
|
2016-11-28 04:40:11 -05:00
|
|
|
--external-ca external-ca Specifications of one or more certificate signing endpoints
|
2016-11-01 15:11:38 -04:00
|
|
|
--force-new-cluster Force create a new cluster from current state
|
2016-07-07 14:43:18 -04:00
|
|
|
--help Print usage
|
2016-11-28 04:40:11 -05:00
|
|
|
--listen-addr node-addr Listen address (format: <ip|interface>[:port]) (default 0.0.0.0:2377)
|
|
|
|
--max-snapshots uint Number of additional Raft snapshots to retain
|
|
|
|
--snapshot-interval uint Number of log entries between Raft snapshots (default 10000)
|
2016-07-24 05:13:06 -04:00
|
|
|
--task-history-limit int Task history retention limit (default 5)
|
2016-07-07 14:43:18 -04:00
|
|
|
```
|
2016-06-13 22:57:19 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
## Description
|
|
|
|
|
2016-07-25 19:24:32 -04:00
|
|
|
Initialize a swarm. The docker engine targeted by this command becomes a manager
|
|
|
|
in the newly created single-node swarm.
|
2016-06-13 22:57:19 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
## Examples
|
2016-06-13 22:57:19 -04:00
|
|
|
|
|
|
|
```bash
|
2016-06-30 21:07:35 -04:00
|
|
|
$ docker swarm init --advertise-addr 192.168.99.121
|
2016-07-20 14:15:08 -04:00
|
|
|
Swarm initialized: current node (bvz81updecsj6wjz393c09vti) is now a manager.
|
2016-07-05 18:39:26 -04:00
|
|
|
|
|
|
|
To add a worker to this swarm, run the following command:
|
2016-07-27 10:14:29 -04:00
|
|
|
|
2016-07-20 14:15:08 -04:00
|
|
|
docker swarm join \
|
|
|
|
--token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx \
|
|
|
|
172.17.0.2:2377
|
|
|
|
|
2016-07-27 10:14:29 -04:00
|
|
|
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
|
2016-06-13 22:57:19 -04:00
|
|
|
```
|
|
|
|
|
2016-07-20 14:15:08 -04:00
|
|
|
`docker swarm init` 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 [swarm join](swarm_join.md).
|
2016-06-29 17:01:25 -04:00
|
|
|
|
2016-07-20 14:15:08 -04:00
|
|
|
After you create the swarm, you can display or rotate the token using
|
|
|
|
[swarm join-token](swarm_join_token.md).
|
2016-07-12 16:06:01 -04:00
|
|
|
|
2016-11-09 17:35:58 -05:00
|
|
|
### `--autolock`
|
|
|
|
|
|
|
|
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 `docker swarm unlock` to reactivate
|
|
|
|
the manager. Autolock can be disabled by running
|
|
|
|
`docker swarm update --autolock=false`. 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.
|
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
### `--cert-expiry`
|
|
|
|
|
|
|
|
This flag sets the validity period for node certificates.
|
|
|
|
|
|
|
|
### `--dispatcher-heartbeat`
|
|
|
|
|
2016-11-24 21:03:28 -05:00
|
|
|
This flag sets the frequency with which nodes are told to use as a
|
2016-07-07 14:43:18 -04:00
|
|
|
period to report their health.
|
|
|
|
|
2016-11-02 15:29:51 -04:00
|
|
|
### `--external-ca`
|
2016-06-30 19:07:25 -04:00
|
|
|
|
|
|
|
This flag sets up the swarm to use an external CA to issue node certificates. The value takes
|
|
|
|
the form `protocol=X,url=Y`. The value for `protocol` specifies what protocol should be used
|
|
|
|
to send signing requests to the external CA. Currently, the only supported value is `cfssl`.
|
|
|
|
The URL specifies the endpoint where signing requests should be submitted.
|
|
|
|
|
2016-06-13 22:57:19 -04:00
|
|
|
### `--force-new-cluster`
|
|
|
|
|
2016-06-30 21:07:35 -04:00
|
|
|
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.
|
2016-06-13 22:57:19 -04:00
|
|
|
|
2016-11-02 15:29:51 -04:00
|
|
|
### `--listen-addr`
|
2016-06-13 22:57:19 -04:00
|
|
|
|
2016-08-30 14:04:41 -04:00
|
|
|
The node listens for inbound swarm manager traffic on this address. The default is to listen on
|
2016-06-30 21:07:35 -04:00
|
|
|
0.0.0.0:2377. It is also possible to specify a network interface to listen on that interface's
|
|
|
|
address; for example `--listen-addr eth0:2377`.
|
|
|
|
|
2016-07-21 13:40:19 -04:00
|
|
|
Specifying a port is optional. If the value is a bare IP address or interface
|
2016-06-30 21:07:35 -04:00
|
|
|
name, the default port 2377 will be used.
|
|
|
|
|
2016-11-02 15:29:51 -04:00
|
|
|
### `--advertise-addr`
|
2016-06-30 21:07:35 -04:00
|
|
|
|
|
|
|
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
|
2016-11-24 21:03:28 -05:00
|
|
|
if the system has a single IP address, and use that IP address with the
|
2016-06-30 21:07:35 -04:00
|
|
|
listening port (see `--listen-addr`). If the system has multiple IP addresses,
|
|
|
|
`--advertise-addr` must be specified so that the correct address is chosen for
|
|
|
|
inter-manager communication and overlay networking.
|
|
|
|
|
|
|
|
It is also possible to specify a network interface to advertise that interface's address;
|
|
|
|
for example `--advertise-addr eth0:2377`.
|
|
|
|
|
2016-07-21 13:40:19 -04:00
|
|
|
Specifying a port is optional. If the value is a bare IP address or interface
|
2016-06-30 21:07:35 -04:00
|
|
|
name, the default port 2377 will be used.
|
2016-06-13 22:57:19 -04:00
|
|
|
|
2017-04-14 19:54:17 -04:00
|
|
|
### `--data-path-addr`
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
### `--task-history-limit`
|
|
|
|
|
|
|
|
This flag sets up task history retention limit.
|
|
|
|
|
2016-11-02 15:29:51 -04:00
|
|
|
### `--max-snapshots`
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
### `--snapshot-interval`
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
2016-12-21 21:13:31 -05:00
|
|
|
### `--availability`
|
|
|
|
|
|
|
|
This flag specifies the availability of the node at the time the node joins a master.
|
|
|
|
Possible availability values are `active`, `pause`, or `drain`.
|
|
|
|
|
|
|
|
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 `--availability=drain` to `docker swarm init`.
|
|
|
|
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
## Related commands
|
2016-06-13 22:57:19 -04:00
|
|
|
|
2017-05-10 18:34:56 -04:00
|
|
|
* [swarm ca](swarm_ca.md)
|
2016-06-13 22:57:19 -04:00
|
|
|
* [swarm join](swarm_join.md)
|
2016-12-19 12:55:51 -05:00
|
|
|
* [swarm join-token](swarm_join_token.md)
|
2016-06-13 22:57:19 -04:00
|
|
|
* [swarm leave](swarm_leave.md)
|
2016-12-19 12:55:51 -05:00
|
|
|
* [swarm unlock](swarm_unlock.md)
|
|
|
|
* [swarm unlock-key](swarm_unlock_key.md)
|
2016-06-13 22:57:19 -04:00
|
|
|
* [swarm update](swarm_update.md)
|