1/4
What is Docker Swarm?
+15 XP on completion
#What is Docker Swarm?
After this lesson you'll know:
- what Swarm Mode is
- the difference between Manager and Worker nodes
- how Swarm provides high-availability services
#A Cluster from your machine
So far you've run Docker on a single host. Swarm turns it into a cluster — multiple machines acting as one Docker host.
Imagine: Your app runs on three servers. One fails. Swarm restarts the containers on the other two. No downtime. No manual intervention.
#Manager vs Worker
Manager = Boss (manages the cluster, assigns tasks)
Worker = Worker (runs containers)
- Manager nodes maintain cluster state (in a Raft database) and assign tasks
- Worker nodes run the containers — they're interchangeable
- A cluster should have 3 or 5 managers (odd number for Raft quorum)
#Activating Swarm
# On the first server (becomes manager)
docker swarm init --advertise-addr 192.168.1.10
# Output shows the join token for workers:
docker swarm join --token SWMTKN-... 192.168.1.10:2377
# On additional servers:
docker swarm join --token SWMTKN-xyz 192.168.1.10:2377
docker node ls # See all nodes in the cluster
#Why Swarm and not Kubernetes?
- Simplicity — Swarm is built into Docker, no extra tools needed
- Compatible — docker-compose.yml works almost 1:1 with
docker stack deploy - Lightweight — runs on 3 small VMs, no resource hog
- Perfect for teams that know Docker but don't need K8s
Kubernetes is more powerful. Swarm is simpler. For 80% of use cases, Swarm is more than enough.
#✋ Try it out
docker swarm init— make your machine a Swarm Manager. What doesdocker node lsshow?- Add a second node (simulate on the same machine:
docker swarm join-token workershows the command) docker swarm leaveon the worker, thendocker swarm leave --forceon the manager — destroy the cluster
#📌 Summary
- Swarm turns multiple Docker hosts into one cluster
- Managers manage, Workers execute — 3 or 5 managers for high availability
- Swarm is the simple alternative to Kubernetes — built-in and Compose compatible
← → to navigate