Skip to main content

Docker Swarm

Updated 3 min read

Share this page

Send the link, quote the definition with a link back, or show it as a card on your own site.

https://softwaredictionary.org/terms/docker-swarm

In short

Docker Swarm is the clustering mode built into Docker Engine: it joins several machines into one swarm and runs containers across them as replicated services.

What is Docker Swarm?

Docker Swarm, officially swarm mode, turns a group of machines running Docker into a single cluster called a swarm. It has been built into Docker Engine since version 1.12 in 2016, so there is nothing extra to install: docker swarm init makes one machine a manager, and other machines join it with a token. It replaced an older standalone tool, now called Classic Swarm, which is no longer developed.

Instead of starting containers one by one, you declare services: which image to run, how many replicas and which ports to publish. Manager nodes store the cluster state and agree on it with the Raft consensus algorithm; they schedule the replicas onto worker nodes and replace any that fail. Swarm also provides overlay networks between machines, a routing mesh that lets any node accept traffic for a published port, rolling updates and encrypted secrets. A whole application can be deployed from a Compose file with docker stack deploy.

If Docker Compose is a recipe cooked in one kitchen, Swarm is the same recipe shared across several kitchens, with a head chef who moves the work elsewhere when one kitchen closes. It suits teams that want clustering with the tools and files they already know, such as small and medium production setups, on-premises servers and edge locations. Mirantis, which bought Docker's enterprise business in 2019, sells commercial support, and swarm mode remains part of the open-source Moby project behind Docker Engine.

Docker Swarm is most often compared with Kubernetes. Both schedule containers across a cluster, restart failed ones and roll out updates, but Swarm keeps to a small set of concepts and reuses the Docker command line and Compose files. Kubernetes has many more features, such as autoscaling, custom resources and operators, and a far larger ecosystem, with managed services from every major cloud. Swarm is easier to learn and run; Kubernetes is the usual choice for large or complex systems.

Key takeaways

  • Docker Swarm, or swarm mode, joins several Docker hosts into one cluster.
  • It has been built into Docker Engine since 2016; Classic Swarm was a separate, retired tool.
  • Managers keep the cluster state with Raft; workers run the containers.
  • Services declare the image, replicas and ports; stacks deploy whole Compose files.
  • It is simpler than Kubernetes but has a much smaller ecosystem.

Example

Creating a swarm and running a servicebash
# On the first machine: create a swarm; this node becomes a manager
docker swarm init --advertise-addr 10.0.0.1

# On every other machine: join with the token that init printed
docker swarm join --token <worker-token> 10.0.0.1:2377

# Run three replicas of a web app spread across the nodes
docker service create --name web --replicas 3 --publish 80:8080 example/web:1.0
docker service ls

# Roll out a new version, one replica at a time by default
docker service update --image example/web:1.1 web

# Or deploy a whole application from a Compose file
docker stack deploy -c compose.yaml shop

Readers ask

Is Docker Swarm still maintained?

Yes. Swarm mode is part of Docker Engine and the open-source Moby project, and it still receives updates. What was retired is Classic Swarm, the separate tool that came before it. Its community and tooling are much smaller than those of Kubernetes, though.

What is the difference between Docker Swarm and Kubernetes?

Both run containers across a cluster. Swarm is built into Docker, uses Compose files and takes minutes to set up; Kubernetes is more complex but offers far more features, extensions and managed cloud services.

What is the difference between Docker Compose and Docker Swarm?

Compose runs a multi-container application on one machine. Swarm runs services across several machines with replicas, failover and rolling updates, and it can deploy the same Compose file as a stack.

See also

Sources

Spotted a mistake or something missing on this page?Suggest an edit

More

Settings