# devops / orchestration / swarm
Orchestration Made Simple with Docker Swarm
Running one container is easy. Running many containers across many servers? That’s where things get messy. Docker Swarm groups multiple hosts into a single cluster to handle load balancing, scaling, and high availability seamlessly.
What is Docker Swarm?
Modern apps don’t run as one container — they need many copies on many servers. Swarm is Docker’s built-in orchestration tool. You tell it what you want, and Swarm decides where it runs.
One Pizza Shop → One standalone Docker host.
Many Shops → A Swarm cluster.
Shop Manager → The Swarm Manager assigning orders to workers.
Kubernetes is more powerful, but Docker Swarm is significantly easier to learn and set up, especially if you already know basic Docker commands.
Core Cluster Concepts
- Swarm Mode
A special Docker mode that enables clustering capabilities via
docker swarm init. - Manager Node
The brain of the cluster. It decides where containers run, handles scaling, and maintains state. There is only one leader at a time.
- Worker Node
The muscle. Executes containers and follows the manager’s instructions. Does not make routing decisions.
Setting Up the Swarm
🌐 Built-in Ingress Overlay
Docker Swarm automatically creates an ingress overlay network. Containers on entirely different physical machines can talk to each other seamlessly. If a user hits Node2 on port 80, but the container is actually on Node1, Swarm automatically routes the traffic.
Services & Auto-Scaling
In Swarm, you don’t run containers directly. You create services. A service says: “Run this container, this many times, and keep it alive no matter what.”
Replicated Mode
You decide the exact number of containers (e.g., --replicas 5). Swarm distributes them dynamically. Best for web apps, APIs, and microservices.
Global Mode
Runs exactly one container per node. Automatically deploys a new container if a new node joins. Best for monitoring agents, log collectors, or security scanners.
Node Management
| Action | Command | What it does | Analogy |
|---|---|---|---|
| Promote | docker node promote worker2 |
Upgrades a worker to a manager. | Employee gets promoted to Manager. |
| Demote | docker node demote manager2 |
Downgrades a manager to a worker. | Manager steps down to regular staff. |
| Drain | docker node update --availability drain worker2 |
Evicts all running tasks and moves them to other nodes. | Shop closed for maintenance, orders go elsewhere. |
| Pause | docker node update --availability pause worker2 |
Keeps current tasks running, but accepts no new tasks. | Shop open, but rejecting new orders right now. |