Skip to main content

Docker Swarm

Docker Swarm is Docker's built-in clustering and orchestration mode. It turns several Docker hosts into one cluster with service scaling, rolling updates, overlay networking, and secrets, as a simpler alternative to Kubernetes.

What Swarm provides

Compose runs services on one host. Swarm runs them across managers and workers with built-in load balancing through a routing mesh, rolling updates, and encrypted secrets. It uses the Raft consensus protocol among managers, so run three or five managers for fault tolerance.

Set up a cluster

Bash
# On the first manager
docker swarm init --advertise-addr 10.0.1.50
# On each worker (token comes from the init output)
docker swarm join --token SWMTKN-1-<token> 10.0.1.50:2377
docker node ls

Deploy and update a service

Bash
docker service create --name payment-api --replicas 6 --publish 8080:8080 \
--network payment-overlay registry.example.com/payment-api:v3.1.0
docker service scale payment-api=10
docker service update --image registry.example.com/payment-api:v3.2.0 \
--update-parallelism 2 --update-delay 10s payment-api
docker service ps payment-api

Stacks with a Compose file

YAML
services:
api:
image: registry.example.com/payment-api:v3.1.0
deploy:
replicas: 6
update_config:
parallelism: 2
delay: 10s
failure_action: rollback
restart_policy:
condition: on-failure
networks:
- payment-overlay
networks:
payment-overlay:
driver: overlay
Bash
docker stack deploy -c compose.yaml payment-stack

Swarm versus Kubernetes

Aspect Swarm Kubernetes
Setup Minutes Significant
Autoscaling None built in HPA and cluster autoscaler
Ecosystem Small Very large
Best fit Small multi-host setups Larger platforms
Remember

Swarm is still part of Docker Engine, but most tooling and hiring assume Kubernetes. Choose Swarm for simplicity, not as a growth path.

Frequently Asked Questions

Is Docker Swarm still used?

Yes, it remains in Docker Engine and suits small teams who want basic multi-host orchestration with little overhead. The wider ecosystem has consolidated around Kubernetes, so many teams treat Swarm as a simple option rather than a long-term platform.

What gap most often pushes teams off Swarm?

The lack of native autoscaling and a much smaller ecosystem of operators, ingress options, and integrations. When a team needs fine-grained scaling or a tool that only supports Kubernetes, migration becomes attractive.

How many manager nodes should a Swarm have?

Use an odd number, usually three or five, so the Raft quorum survives failures. A single manager is a single point of failure for the control plane.

Found a mistake, an outdated step or a broken link?