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 [COMMAND] [OPTIONS]

PARAMETERS

init
    Initialize a swarm cluster on the current node, making it a manager.

join
    Join the current node to an existing swarm as a manager or worker.

join-token
    Manage join tokens for worker or manager nodes.

leave
    Leave the swarm (force with --force).

unlock
    Unlock a locked swarm using the unlock key.

unlock-key
    Manage the unlock key for a locked swarm.

update
    Update swarm configuration (e.g., autolock).

--help
    Show help for docker swarm.

DESCRIPTION

Docker Swarm is Docker's native clustering and orchestration solution for running containerized applications across multiple hosts. The docker swarm command enables initialization, joining, and management of swarms, which are groups of Docker nodes working together as a single system.

In Swarm mode, nodes are either managers (handling orchestration) or workers (running tasks). Use docker swarm init to create a single-node swarm on the manager. Other hosts join via docker swarm join with a generated token. Services deployed with docker service create are automatically scheduled, scaled, and maintained across the cluster, with built-in load balancing, rolling updates, and failover.

Key features include service discovery, routing mesh, secrets management, and config objects. This command supports multi-manager setups for high availability. Swarm integrates seamlessly with Docker Compose via docker stack deploy. Ideal for production workloads requiring resilience without external orchestrators like Kubernetes.

CAVEATS

Only one swarm per host; requires Docker 1.12+; manager nodes store Raft logs (avoid resource-constrained hosts); deprecated external CA support in newer versions.

BASIC USAGE EXAMPLES

docker swarm init --advertise-addr 192.168.1.10
docker swarm join --token SWMTKN-1-... 192.168.1.10:2377

KEY OPTIONS (COMMON)

init: --autolock, --listen-addr
join: --token, --role
update: --autolock

HISTORY

Introduced in Docker 1.12.0 (July 2016) replacing deprecated Docker Machine cluster. Evolved with multi-manager HA, overlay networking v2, secrets (1.13), and autoscaling support.

SEE ALSO

docker(1), docker-node(1), docker-service(1), docker-stack(1)

Copied to clipboard