2016-06-13 22:57:19 -04:00
# swarm init
2023-01-06 13:04:05 -05:00
<!-- - MARKER_GEN_START -->
2016-07-20 14:15:08 -04:00
Initialize a swarm
2016-07-07 14:43:18 -04:00
2023-01-06 13:04:05 -05:00
### Options
2023-12-13 09:16:56 -05:00
| Name | Type | Default | Description |
|:--------------------------------------------|:--------------|:---------------|:-----------------------------------------------------------------------------------------------------------------------------|
| [`--advertise-addr` ](#advertise-addr ) | `string` | | Advertised address (format: `<ip\|interface>[:port]` ) |
| [`--autolock` ](#autolock ) | | | Enable manager autolocking (requiring an unlock key to start a stopped manager) |
| [`--availability` ](#availability ) | `string` | `active` | Availability of the node (`active`, `pause` , `drain` ) |
| `--cert-expiry` | `duration` | `2160h0m0s` | Validity period for node certificates (ns\|us\|ms\|s\|m\|h) |
| [`--data-path-addr` ](#data-path-addr ) | `string` | | Address or interface to use for data path traffic (format: `<ip\|interface>` ) |
| [`--data-path-port` ](#data-path-port ) | `uint32` | `0` | 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. |
| [`--default-addr-pool` ](#default-addr-pool ) | `ipNetSlice` | | default address pool in CIDR format |
| `--default-addr-pool-mask-length` | `uint32` | `24` | default address pool subnet mask length |
| `--dispatcher-heartbeat` | `duration` | `5s` | Dispatcher heartbeat period (ns\|us\|ms\|s\|m\|h) |
| [`--external-ca` ](#external-ca ) | `external-ca` | | Specifications of one or more certificate signing endpoints |
| [`--force-new-cluster` ](#force-new-cluster ) | | | Force create a new cluster from current state |
| [`--listen-addr` ](#listen-addr ) | `node-addr` | `0.0.0.0:2377` | Listen address (format: `<ip\|interface>[:port]` ) |
| [`--max-snapshots` ](#max-snapshots ) | `uint64` | `0` | Number of additional Raft snapshots to retain |
| [`--snapshot-interval` ](#snapshot-interval ) | `uint64` | `10000` | Number of log entries between Raft snapshots |
| `--task-history-limit` | `int64` | `5` | Task history retention limit |
2023-01-06 13:04:05 -05:00
<!-- - MARKER_GEN_END -->
2016-06-13 22:57:19 -04:00
2017-02-07 18:42:48 -05:00
## Description
2023-12-13 09:16:56 -05:00
Initialize a swarm. The Docker Engine targeted by this command becomes a manager
2016-07-25 19:24:32 -04:00
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
2021-08-21 08:54:14 -04:00
```console
2016-06-30 21:07:35 -04:00
$ docker swarm init --advertise-addr 192.168.99.121
2021-08-21 08:54:14 -04:00
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
2023-12-13 09:16:56 -05:00
docker swarm join --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-1awxwuwd3z9j1z3puu7rcgdbx 172.17.0.2:2377
2016-07-20 14:15:08 -04:00
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
```
2023-12-13 09:16:56 -05:00
The `docker swarm init` command 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
2020-04-19 09:43:08 -04:00
[swarm join-token ](swarm_join-token.md ).
2016-07-12 16:06:01 -04:00
2023-12-13 09:16:56 -05:00
### <a name="autolock"></a> Protect manager keys and data (--autolock)
2016-11-09 17:35:58 -05:00
2023-12-13 09:16:56 -05:00
The `--autolock` flag enables automatic locking of managers with an encryption
key. The private keys and data stored by all managers are protected by the
encryption key printed in the output, and is inaccessible without it. Make sure
to store this key securely, in order to reactivate a manager after it restarts.
Pass the key to the `docker swarm unlock` command to reactivate the manager.
You can disable autolock 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-11-09 17:35:58 -05:00
2023-12-13 09:16:56 -05:00
### <a name=""></a> Configure node healthcheck frequency (--dispatcher-heartbeat)
2016-07-07 14:43:18 -04:00
2023-12-13 09:16:56 -05:00
The `--dispatcher-heartbeat` flag sets the frequency at which nodes are told to
report their health.
2016-07-07 14:43:18 -04:00
2023-12-13 09:16:56 -05:00
### <a name="external-ca"></a> Use an external certificate authority (--external-ca)
2016-07-07 14:43:18 -04:00
2023-12-13 09:16:56 -05: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-07-07 14:43:18 -04:00
2023-12-13 09:16:56 -05:00
### <a name="force-new-cluster"></a> Force-restart node as a single-mode manager (--force-new-cluster)
2016-06-30 19:07:25 -04:00
2023-12-13 09:16:56 -05: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-30 19:07:25 -04:00
2023-12-13 09:16:56 -05:00
### <a name="listen-addr"></a> Specify interface for inbound control plane traffic (--listen-addr)
2016-06-13 22:57:19 -04:00
2023-12-13 09:16:56 -05:00
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 `--listen-addr
eth0:2377`.
2016-06-30 21:07:35 -04:00
2016-07-21 13:40:19 -04:00
Specifying a port is optional. If the value is a bare IP address or interface
2023-12-13 09:16:56 -05:00
name, the default port 2377 is used.
2016-06-30 21:07:35 -04:00
2023-12-13 09:16:56 -05:00
### <a name="advertise-addr"></a> Specify interface for outbound control plane traffic (--advertise-addr)
2016-06-30 21:07:35 -04:00
2023-12-13 09:16:56 -05:00
The `--advertise-addr` 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 `--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.
2016-06-30 21:07:35 -04:00
2023-12-13 09:16:56 -05:00
It is also possible to specify a network interface to advertise that
interface's address; for example `--advertise-addr eth0:2377` .
2016-06-30 21:07:35 -04:00
2016-07-21 13:40:19 -04:00
Specifying a port is optional. If the value is a bare IP address or interface
2023-12-13 09:16:56 -05:00
name, the default port 2377 is used.
### <a name="data-path-addr"></a> Specify interface for data traffic (--data-path-addr)
2016-06-13 22:57:19 -04:00
2023-12-13 09:16:56 -05:00
The `--data-path-addr` 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 you can separate the container's
data traffic from the management traffic of the cluster.
2017-04-14 19:54:17 -04:00
2023-12-13 09:16:56 -05:00
If unspecified, the IP address or interface of the advertise address is used.
2017-04-14 19:54:17 -04:00
2023-12-13 09:16:56 -05:00
### <a name="data-path-port"></a> Configure port number for data traffic (--data-path-port)
2018-11-26 16:04:39 -05:00
2023-12-13 09:16:56 -05:00
The `--data-path-port` 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 isn't set, or if it's 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;
2018-11-26 16:04:39 -05:00
2021-08-21 08:54:14 -04:00
```console
$ docker swarm init --data-path-port=7777
2018-11-26 16:04:39 -05:00
```
2021-08-21 08:54:14 -04:00
2018-11-26 16:04:39 -05:00
After the swarm is initialized, use the `docker info` command to verify that
the port is configured:
2021-08-21 08:54:14 -04:00
```console
$ docker info
< ... >
2020-03-15 10:11:43 -04:00
ClusterID: 9vs5ygs0gguyyec4iqf2314c0
Managers: 1
Nodes: 1
Data Path Port: 7777
2021-08-21 08:54:14 -04:00
< ... >
2018-11-26 16:04:39 -05:00
```
2023-12-13 09:16:56 -05:00
### <a name="default-addr-pool"></a> Specify default subnet pools (--default-addr-pool)
2018-07-28 22:44:11 -04:00
2023-12-13 09:16:56 -05:00
The `--default-addr-pool` flag specifies default subnet pools for global scope
networks. For example, to specify two address pools:
2018-07-28 22:44:11 -04:00
2023-12-13 09:16:56 -05:00
```console
$ docker swarm init \
--default-addr-pool 30.30.0.0/16 \
--default-addr-pool 40.40.0.0/16
```
2016-07-07 14:43:18 -04:00
2023-12-13 09:16:56 -05:00
Use the `--default-addr-pool-mask-length` flag to specify the default subnet
pools mask length for the subnet pools.
2016-07-07 14:43:18 -04:00
2023-12-13 09:16:56 -05:00
### <a name="max-snapshots"></a> Set limit for number of snapshots to keep (--max-snapshots)
2016-11-02 15:29:51 -04:00
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.
2023-12-13 09:16:56 -05:00
### <a name="snapshot-interval"></a> Configure Raft snapshot log interval (--snapshot-interval)
2016-11-02 15:29:51 -04:00
2023-12-13 09:16:56 -05:00
The `--snapshot-interval` flag specifies how many log entries to allow in
between Raft snapshots. Setting this to a high 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-11-02 15:29:51 -04:00
2023-12-13 09:16:56 -05:00
### <a name="availability"></a> Configure the availability of a manager (--availability)
2016-12-21 21:13:31 -05:00
2023-12-13 09:16:56 -05:00
The `--availability` flag specifies the availability of the node at the time
the node joins a master. Possible availability values are `active` , `pause` , or
`drain` .
2016-12-21 21:13:31 -05:00
2023-12-13 09:16:56 -05:00
This flag is useful in certain situations. For example, a cluster may want to
have dedicated manager nodes that don't serve as worker nodes. You can do this
2016-12-21 21:13:31 -05:00
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 )
2020-04-19 09:43:08 -04: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 )
2020-04-19 09:43:08 -04:00
* [swarm unlock-key ](swarm_unlock-key.md )
2016-06-13 22:57:19 -04:00
* [swarm update ](swarm_update.md )