Deploying and Managing Multi-Node Clusters with Docker Swarm

Docker Swarm turns a group of Docker nodes into a secure, highly available cluster with built-in application orchestration. This article covers building a multi-node swarm, deploying a microservices app declaratively, and performing rolling updates without losing desired-state consistency.

Docker SwarmContainer OrchestrationRolling Updates

~4 min read · Updated Sep 5, 2026

Introduction

Docker Swarm is both a secure cluster of Docker nodes and an intelligent application orchestrator. While Kubernetes has become the dominant orchestration platform, Swarm remains a lightweight alternative well suited to smaller environments that don't need the complexity and learning curve of a full Kubernetes setup.

Managers and Workers

A swarm consists of manager nodes, which run control plane services and orchestration logic, and optional worker nodes, which run application workloads. Both types can be physical machines, VMs, or cloud instances, as long as they run Docker and can communicate reliably over the network. By default, managers also run application workloads, though production environments often dedicate them purely to control plane duties.

Building a Swarm

A swarm is initialized on the first intended manager node:

docker swarm init

This command outputs a docker swarm join command containing a token, which can be run on other nodes to add them as workers:

docker swarm join --token SWMTKN-1-... 172.31.40.192:2377

For high availability, production swarms typically run three managers so the cluster can tolerate the loss of one. A separate join token for managers can be generated with:

docker swarm join-token manager

The state of the cluster can be checked at any time with:

docker node ls

One manager is always shown as Leader, with the others marked Reachable, reflecting Swarm's active/passive high-availability model.

Deploying an App

Swarm apps are defined using a Compose file, extended with Swarm-specific deploy settings such as replica counts, update behavior, and restart policies. A typical service definition might request four replicas, update two at a time with a delay between batches, and roll back automatically on failure.

The core concept behind Swarm is desired state — what the Compose file specifies the app should look like. Deploying an app is done with:

docker stack deploy -c compose.yaml ddd

Swarm then works to make the cluster's observed state match this desired state, distributing replicas evenly across available nodes. The status of a deployed app can be checked with:

docker stack ps ddd
docker stack services ddd

Managing Apps Declaratively

Swarm apps can be managed either imperatively, by running direct CLI commands, or declaratively, by editing the Compose file and redeploying. The declarative approach is strongly preferred, since imperative changes — like manually scaling a service — can be silently overwritten the next time the Compose file is redeployed, since Swarm always reconciles the cluster back to what the file describes.

Updating an app, such as scaling replicas and switching to a new image version, is done entirely by editing the Compose file and re-running:

docker stack deploy -c compose.yaml ddd

Swarm then performs a controlled rolling update, replacing replicas in batches according to the rules defined under deploy.update_config, and rolling back automatically if failures occur.

Cleaning Up

An app can be removed with:

docker stack rm ddd

Note that this removes services and networks but not volumes, since Swarm intentionally decouples volume lifecycles from the app itself, requiring an explicit docker volume rm to delete stored data.

Conclusion

Docker Swarm offers a genuinely capable, if less popular, way to run highly available, self-healing microservices applications across a cluster of nodes. Managing everything declaratively through Compose files — kept under version control — ensures the cluster's actual state always reflects what's intended, and makes Swarm a practical stepping stone toward learning more advanced orchestration platforms like Kubernetes.

Written & researched by Dr. Shahin Siami

Related Articles

How Docker Uses Linux Security Technologies: Namespaces, Cgroups, and More

Docker's security model is built on layered defense, combining well-established Linux kernel technologies with sensible defaults out of the box. This article explains how namespaces, control groups, capabilities, mandatory access control, and seccomp work together to isolate and secure containers.

Continue

Managing Persistent Data in Docker with Volumes

Containers get a temporary writable layer by default, which disappears the moment a container is deleted — fine for scratch data, but risky for anything worth keeping. This article explains how Docker volumes decouple persistent data from container lifecycles, and walks through creating, using, and sharing them safely.

Continue

How Docker Overlay Networks Work: VXLAN Under the Hood

Overlay networks let containers on different hosts communicate as if they shared a single flat network, forming the backbone of most cloud-native microservices apps. This article covers how to build, encrypt, and test a Docker overlay network across a Swarm cluster, and explains the VXLAN tunneling technology powering it behind the scenes.

Continue

Connecting Docker Containers to VLANs and Load Balancing with Swarm

Beyond basic bridge networks, Docker can connect containers directly to existing physical VLANs, resolve service names automatically, and distribute traffic across a Swarm cluster. This article covers the macvlan driver, Docker's built-in service discovery, and Swarm's ingress load balancing mesh.

Continue

Understanding Docker Networking: CNM, Libnetwork, and Bridge Networks

Docker networking is built on an open design called the Container Network Model, implemented through libnetwork and extended by pluggable drivers. This article covers the theory behind Docker networking and walks through creating and testing single-host bridge networks, including name resolution and port mapping.

Continue

Building and Running WebAssembly Apps as Docker Containers

WebAssembly (Wasm) is emerging as a lightweight alternative to traditional containers, and Docker now supports building, sharing, and running Wasm apps using familiar tools. This article walks through writing a simple Wasm app with Spin, containerizing it with Docker, and running it as a Wasm container.

Continue