LinuxCommandLibrary

docker-swarm

Orchestrate and manage a cluster of Docker nodes

TLDR

Initialize a swarm cluster

$ docker swarm init
copy

Display the token to join a manager or a worker
$ docker swarm join-token [worker|manager]
copy

Join a new node to the cluster
$ docker swarm join --token [token] [manager_node_url:2377]
copy

Remove a worker from the swarm (run inside the worker node)
$ docker swarm leave
copy

Display the current CA certificate in PEM format
$ docker swarm ca
copy

Rotate the current CA certificate and display the new certificate
$ docker swarm ca --rotate
copy

Change the valid period for node certificates
$ docker swarm update --cert-expiry [hours]h[minutes]m[seconds]s
copy

SYNOPSIS

docker swarm [OPTIONS]

PARAMETERS

init
    Initialize a new swarm.

join
    Join an existing swarm as a worker or manager.

leave
    Leave the current swarm.

update
    Update the swarm configuration.

inspect
    Display detailed information about the swarm.

--advertise-addr ADDR
    IP address or interface to use for communication between swarm nodes.

--autolock
    Enable or disable swarm autolocking.

--data-path-addr ADDR
    Address used for data path traffic.

--default-addr-pool IP_POOL
    Default address pool (CIDR) for service networks

--dispatcher-heartbeat-period DURATION
    Node dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s)

--external-ca CA
    Specifications of one or more certificate authorities that are trusted.

--force-new-cluster
    Force create a new cluster from current state.

--listen-addr ADDR
    Listen address used for inter-manager communication.

--max-snapshots int
    Number of additional Raft snapshots to retain.

--snapshot-interval DURATION
    Number of log entries between Raft snapshots (default 10000)

DESCRIPTION

The `docker swarm` command is the primary interface for managing Docker Swarm, Docker's built-in orchestration tool. Swarm mode allows you to create and manage a cluster of Docker Engines, enabling you to deploy and scale applications across multiple machines. It provides features such as service discovery, load balancing, rolling updates, and fault tolerance. Using `docker swarm init`, you initialize a new swarm, designating the current machine as the manager node. Then you use `docker swarm join` to add worker nodes or additional manager nodes to the swarm. Services, which define how containers are deployed and run, are created using `docker service create`. You can scale services using `docker service scale`, update service configurations using `docker service update`, and monitor the swarm's health using `docker node ls` and `docker service ps`. The command is integral for building distributed, resilient applications using Docker.

SWARM INITIALIZATION

docker swarm init starts a new Swarm. The node where this command is executed becomes the first manager node.
Example: `docker swarm init --advertise-addr eth0`

JOINING A SWARM

docker swarm join allows other nodes to join the Swarm, either as workers or additional managers. It requires the manager's address and token.
Example: `docker swarm join --token SWMTKN-1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 192.168.1.100:2377`

SECURITY

Swarm communication is secured by mutual TLS. Each node has a cryptographic identity.
Important: Protect your swarm tokens. Compromised tokens can allow unauthorized nodes to join your swarm.

SEE ALSO

docker service(1), docker node(1)

Copied to clipboard