Docker Swarm is the native container orchestration mode of Docker Engine that joins several hosts into one cluster, called a swarm, and runs declaratively defined services across them. In the field of containers and cloud infrastructure, it is usually described by its official name, swarm mode, which has been part of the Docker Engine since version 1.12 and replaced the older standalone Docker Swarm product.
Swarm mode keeps the familiar Docker command line and the Compose file format, so teams can move from a single host to a small cluster with minimal new concepts. It provides scheduling, service discovery, load balancing, rolling updates and encrypted node communication without any additional software.
How Docker Swarm organizes a cluster
A swarm consists of manager nodes and worker nodes, all running the same Docker Engine. Managers hold the cluster state and make scheduling decisions, while workers only execute the tasks assigned to them. A manager can also run workloads unless it is drained, which is a common choice in small clusters.
The managers replicate cluster state with the Raft consensus algorithm. Raft requires a majority quorum of managers to accept any change, so a swarm with three managers tolerates one failure and a swarm with five managers tolerates two. If quorum is lost, existing containers keep running, but no new scheduling or updates are possible until quorum is restored.
The table below shows how the number of managers affects fault tolerance.
| Managers | Quorum size | Failures tolerated | Typical use |
|---|---|---|---|
| 1 | 1 | 0 | Development and testing |
| 3 | 2 | 1 | Small production clusters |
| 5 | 3 | 2 | Larger or critical clusters |
| 7 | 4 | 3 | Rarely needed; adds Raft overhead |
An odd number of managers is recommended because an even number adds no extra tolerance. Running more than seven managers is discouraged, since every write must be replicated to a majority, which slows consensus without improving resilience.
Services, tasks and the desired state model
The central object in Docker Swarm is the service, a declaration of which image to run, how many copies, which networks and volumes to attach and how updates should proceed. The managers continuously compare this desired state with the actual state and create or remove tasks to close any gap, a process known as reconciliation.
Each task is a single container bound to a node. When a node fails, its tasks are marked as down and the scheduler reschedules replacements on healthy nodes. A stack groups several services defined in one Compose file and deploys them together with a single command.
The following table summarizes the main service modes and objects.
| Object | What it represents | Key behavior |
|---|---|---|
| Replicated service | A fixed number of identical tasks | Spread across available nodes |
| Global service | One task on every eligible node | Suits agents such as log shippers |
| Task | One container assigned to a node | Replaced, never moved, on failure |
| Stack | Services from one Compose file | Deployed and removed as a unit |
| Secret and config | Encrypted or plain data for services | Mounted into containers at runtime |
Networking and load balancing in swarm mode
Docker Swarm connects services through overlay networks, which use VXLAN encapsulation to give containers on different hosts a shared virtual network. Every service receives a stable virtual IP address and a DNS name, so other services can reach it by name regardless of where its tasks run.
Published ports use the routing mesh, an ingress network that accepts traffic on the published port of every node and forwards it to a healthy task through IPVS-based load balancing. A request can therefore arrive at a node that runs no copy of the service and still be served. Operators who need client source addresses or direct routing can switch to host mode publishing, which bypasses the mesh.
Communication between nodes is protected by mutual TLS with certificates issued by an internal certificate authority on the managers, and certificates rotate automatically. Overlay data traffic is not encrypted by default, but it can be encrypted with IPsec by creating the network with the encrypted option, at a measurable performance cost.
Docker Swarm compared with other orchestrators
Docker Swarm competes with Kubernetes and managed services such as Amazon ECS, and the choice usually turns on operational simplicity versus ecosystem breadth. Swarm is far easier to install and run, while Kubernetes offers more extension points, a larger tool ecosystem and wider support from cloud providers.
The comparison below covers the attributes that most often decide the choice.
| Attribute | Docker Swarm | Kubernetes | Amazon ECS |
|---|---|---|---|
| Setup effort | One init command | Significant, often managed | Managed by AWS |
| Configuration format | Compose files | YAML manifests and Helm charts | Task definitions |
| Autoscaling | Not built in | Horizontal and cluster autoscalers | Service and capacity autoscaling |
| Extensibility | Limited plugins | Custom resources and operators | AWS integrations |
| Ecosystem size | Small | Very large | AWS-centered |
| Best fit | Small to medium clusters | Large, complex platforms | Workloads committed to AWS |
Docker Swarm should also be distinguished from Docker Compose. Compose runs a multi-container application on a single host, while swarm mode deploys the same file format across many hosts with scheduling and self-healing.
Operating a swarm in practice
A swarm is created with docker swarm init on the first manager, and other nodes join with a join token that determines whether they become managers or workers. Services are then deployed with docker service create or, more commonly, with docker stack deploy and a Compose file.
Rolling updates are configured per service: the update parallelism, the delay between batches and the failure action decide how quickly a new image reaches production. Setting the failure action to rollback and defining a container health check lets the swarm stop a faulty release automatically.
The decision table below lists typical operational choices.
| Situation | Recommended setting | Reason |
|---|---|---|
| Production cluster | Three or five managers | Survives manager failure |
| Busy managers | Drain managers from workloads | Protects Raft responsiveness |
| Stateful database | Placement constraint by node label | Keeps data on the right host |
| Risky release | Parallelism 1 with automatic rollback | Limits the blast radius |
| Credentials | Swarm secrets, not environment variables | Encrypted at rest and in transit |
Limitations and common mistakes
The main limitation of Docker Swarm is its narrow feature set and slower development pace. It has no built-in autoscaling, a limited storage integration model and few third-party operators, so teams that outgrow it often face a migration to Kubernetes later.
- Losing manager quorum through an even manager count or by placing all managers in one failure domain.
- Storing state in local volumes without placement constraints, which leaves data behind when tasks are rescheduled.
- Assuming overlay traffic is encrypted when the encrypted network option was never enabled.
- Forgetting to back up the Raft state directory on managers, which is needed to recover a destroyed cluster.
- Leaving the autolock feature disabled, so stolen manager disks expose Raft encryption keys.
The short version
Docker Swarm lets a group of ordinary servers act like one large computer for running containers. You tell it what you want, for example five copies of a web application, and it decides which machine runs each copy.
If a machine breaks, Swarm notices and starts the missing copies elsewhere. It also spreads incoming visitors across the copies. The key idea is that you describe the result you want, and Swarm keeps the cluster matching that description on its own.
Where it makes a difference
A regional logistics company runs its shipment tracking portal on four virtual machines: three managers that also run light workloads and one larger worker. The team already used Docker Compose in development, so it deploys the same file as a stack with six replicas of the web service, two replicas of an API and a single database pinned to the worker by a node label.
During a routine cloud maintenance event, one manager is restarted without warning. The remaining two managers keep quorum, the scheduler starts replacement tasks within seconds, and the routing mesh sends customer traffic to healthy replicas. Later, a faulty release fails its health check after the first batch, and the configured rollback restores the previous version automatically. The two-person operations team avoided the cost of running a Kubernetes control plane while still getting self-healing and zero-downtime updates.