# Docker Swarm | Cycle.io

Canonical URL: https://cycle.io/learn/common-orchestrator-docker-swarm

## Docker Swarm.

Docker Swarm is the native container orchestration tool developed by Docker, designed to manage clusters of Docker containers. Unlike Kubernetes, Docker Swarm is tightly integrated with the Docker ecosystem, offering a simpler approach to container orchestration. Docker Swarm has fewer features and fewer users than Kubernetes, but it is easier to set up and use, especially in smaller environments.

This page covers what swarm mode is, its status as of November 2026, a tested tutorial and a comparison with Kubernetes. For the general idea of orchestration, see the [introduction to container orchestration](https://cycle.io/learn/introduction-to-container-orchestration).

### What is Docker Swarm?

Docker Swarm, also called swarm mode, is the container orchestrator built into Docker Engine. It joins several Docker hosts into one cluster. Manager nodes store cluster state with the Raft consensus algorithm and schedule work, worker nodes run containers, and Swarm keeps each service at the number of replicas you ask for.

Swarm mode ships with every Docker Engine install. You turn it on with `docker swarm init`, and from then on the same `docker` CLI manages nodes, services, networks and secrets. The orchestration code comes from SwarmKit, an open-source library in the Moby project that Docker Engine embeds.

The main building blocks:

-   **Nodes:** each Docker Engine in the swarm is a node. A node is either a manager or a worker.
-   **Services and tasks:** a service is the definition of what to run (image, replicas, ports, networks, update policy). Swarm turns it into tasks, and each task runs one container. A replicated service runs a set number of tasks; a global service runs one task on every node.
-   **Stacks:** a group of services deployed together from a Compose-format file with `docker stack deploy`.
-   **Overlay networking:** services on different hosts talk over VXLAN-based [overlay networks](https://cycle.io/learn/overlay-networks) that Swarm creates and manages.
-   **Service discovery:** built-in DNS lets containers find each other by service name. By default the name resolves to a virtual IP that load-balances across the service's tasks.
-   **Routing mesh:** a published port is open on every node. A request to any node is forwarded to a healthy task, even on a node that runs no task for that service.
-   **Secrets and configs:** secrets are stored in the managers' encrypted Raft log and mounted into containers as in-memory files under `/run/secrets/`. Configs deliver non-sensitive files, such as an nginx config, in a similar way but are mounted directly into the container's filesystem.
-   **Rolling updates and rollback:** an image or configuration change is rolled out a few tasks at a time, with a delay between batches, and can roll back automatically on failure.

#### Docker swarm mode vs classic Swarm

Two different products have used the name "Docker Swarm":

-   **Classic Swarm** (standalone Swarm) was a separate program, usually run from the `swarm` image, that turned a pool of Docker hosts into a single virtual host. Its [repository](https://github.com/docker/classicswarm) was archived on February 1, 2021 and it is no longer developed.
-   **Swarm mode** arrived in Docker Engine 1.12 in 2016 and is what "Docker Swarm" means today. Commands such as `docker swarm`, `docker service` and `docker stack` all belong to swarm mode.

Tutorials that run the `swarm` image or point Docker at an external cluster store such as Consul describe classic Swarm.

### Docker Swarm architecture

Docker Swarm uses a manager-worker architecture, in which designated nodes manage the cluster and schedule services. The components are:

-   **Manager nodes:** manage the swarm. They handle scheduling, cluster state and coordination between nodes. Manager nodes use the Raft consensus algorithm to keep the cluster state consistent, and one manager is elected leader. By default managers also run workloads.
-   **Worker nodes:** run the tasks the managers assign to them and report their status back.

Raft needs a majority of managers to agree, so a swarm with N managers survives (N-1)/2 manager failures. Three managers tolerate one failure and five tolerate two. Docker recommends an odd number of managers, because adding a fourth manager to three does not raise the number of failures the cluster can survive, and no more than seven managers in one swarm.

Docker Swarm uses services to define applications. Each service describes a set of identical tasks, and the managers spread those tasks across the nodes in the cluster.

### Is Docker Swarm dead?

No. Swarm mode is still part of Docker Engine and still receives fixes, but feature development has slowed. As of November 2026:

-   **Docker Engine still ships and maintains swarm mode.** Docker Engine 29.10.0, released November 16, 2026 ([release notes](https://docs.docker.com/engine/release-notes/29/)), includes several Swarm and overlay networking fixes, and 29.9.3 (November 3, 2026) patched two Swarm security issues, one of them in SwarmKit.
-   **Docker says development has slowed.** Docker's [page of deprecated and retired products](https://docs.docker.com/retired/) lists SwarmKit under its open-source projects and says that while swarm mode remains functional, development has slowed in favor of Kubernetes-based solutions. Swarm mode itself is not on Docker Engine's [deprecated features list](https://docs.docker.com/engine/deprecated/); the only Swarm entry there is classic Swarm.
-   **Mirantis supports Swarm commercially.** Mirantis acquired Docker's enterprise platform business in November 2019. In July 2025 it [announced five more years of Swarm support](https://www.mirantis.com/company/press-center/company-news/mirantis-extends-swarm-support-another-five-years/) and [stated](https://www.mirantis.com/blog/mirantis-guarantees-long-term-support-for-swarm/) that Swarm will be fully supported through at least 2030 as part of Mirantis Kubernetes Engine (MKE) 3.
-   **Classic standalone Swarm is the one that is gone.** It was archived in 2021, as described in the section above.

Swarm is safe to keep running, but expect few new features and fewer third-party integrations over time.

### Docker Swarm tutorial: deploy a stack

The steps below create a single-node swarm, add a secret, deploy a stack from a Compose-format file, scale it and roll out a new image. You need a Linux host with Docker Engine.

The examples use two versions of a small web image, `web:1` and `web:2`, that print their version and container hostname. They were built locally on the test host. The output shown comes from Docker Engine 24.0.7 on Ubuntu 24.04; newer releases can print extra notices. On a multi-node swarm, push your images to a registry that every node can reach, because each node pulls the image itself.

#### 1\. Initialize swarm mode

Run `docker swarm init` on the machine that will be the first manager:

```bash
docker swarm init
```

```
Swarm initialized: current node (y4clbbjghbmlumgn3fpy5poga) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-382oix7v...-1m0dpbkwztt9ydvtafwdz28wp 10.0.2.15:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
```

If the host has more than one IP address, `--advertise-addr` is required. Pass the address the other nodes should use to reach this manager (port 2377 is the default). The examples on this page use 10.0.2.15, the test VM's address; replace it with your manager's IP address:

```bash
docker swarm init --advertise-addr 10.0.2.15
```

Check the node list. The `*` marks the node you are connected to:

```bash
docker node ls
```

```
ID                            HOSTNAME   STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
y4clbbjghbmlumgn3fpy5poga *   pagetest   Ready     Active         Leader           24.0.7
```

Swarm also created an overlay network called `ingress`, which carries routing mesh traffic. `docker network ls` shows it with the `swarm` scope.

#### 2\. Create a secret

Secrets are only available to swarm services, not to containers started with `docker run`. Create one from standard input:

```bash
printf 'example-password' | docker secret create db_password -
docker secret ls
```

```
lmh1lbps0yjsxbkaqwm6hrrfl
ID                          NAME          DRIVER    CREATED         UPDATED
lmh1lbps0yjsxbkaqwm6hrrfl   db_password             2 seconds ago   2 seconds ago
```

In real use, pipe the value from a file or password manager so it stays out of shell history.

#### 3\. Write a stack file

A stack file uses the same Compose format as [Docker Compose](https://cycle.io/learn/docker-compose). Swarm reads the `deploy` section, which plain `docker compose up` applies only in part. `docker stack deploy` does not build images, so they must already exist. Save this as `stack.yaml`:

```yaml
services:
  web:
    image: web:1
    ports:
      - "8080:8080"
    secrets:
      - db_password
    deploy:
      replicas: 3
      update_config:
        parallelism: 1
        delay: 5s
        order: start-first
        failure_action: rollback
      restart_policy:
        condition: on-failure

secrets:
  db_password:
    external: true
```

What the `deploy` keys do:

-   `replicas: 3` runs three tasks of the service.
-   `update_config` replaces one task at a time, waits 5 seconds between tasks, starts the new task before stopping the old one (`start-first`) and rolls back if the update fails.
-   `restart_policy` restarts a task only when its container exits with an error.
-   `external: true` tells Swarm the secret already exists, so the stack does not create or delete it.

#### 4\. Deploy with docker stack deploy

```bash
docker stack deploy -c stack.yaml demo
```

```
Creating network demo_default
Creating service demo_web
```

Newer Docker CLI releases also print a notice that tasks will be created in the background, because `--detach` defaults to true. Add `--detach=false` to make the command wait until the services converge.

Swarm prefixes every object with the stack name, so the service is `demo_web` and its network is the overlay network `demo_default`. List the stack's services and tasks:

```bash
docker stack services demo
docker service ps demo_web
```

```
ID             NAME       MODE         REPLICAS   IMAGE     PORTS
vyjvrvmz0kxa   demo_web   replicated   3/3        web:1     *:8080->8080/tcp
ID             NAME         IMAGE     NODE       DESIRED STATE   CURRENT STATE           ERROR     PORTS
kz627jr6yvhk   demo_web.1   web:1     pagetest   Running         Running 6 seconds ago
4npcrud9gjlz   demo_web.2   web:1     pagetest   Running         Running 6 seconds ago
ltq80b3h4mv2   demo_web.3   web:1     pagetest   Running         Running 6 seconds ago
```

Running `docker stack deploy` again with an edited file updates the stack in place. Add `--prune` to remove services that are no longer in the file.

#### 5\. Test the routing mesh and the secret

Port 8080 is published through the routing mesh, so any node's address reaches the service, and requests are spread across the tasks. Replace 10.0.2.15 (the test host) with the IP address of any node in your swarm:

```bash
for i in 1 2 3 4 5 6; do curl -s http://10.0.2.15:8080/; done
```

```
web v1 on 79857b1aa4a9
web v1 on 165323d83f1b
web v1 on 4a1b4112558a
web v1 on 79857b1aa4a9
web v1 on 165323d83f1b
web v1 on 4a1b4112558a
```

Inside a task, the secret is a file under `/run/secrets`, and the service name resolves through Swarm's DNS:

```bash
docker exec <container-id> cat /run/secrets/db_password
docker exec <container-id> wget -qO- http://web:8080/
```

```
example-password
web v1 on 34010bff2537
```

Find a container ID with `docker ps --filter name=demo_web`. Inside the stack's network, the short service name `web` resolves to the service's virtual IP, which balances requests across the tasks.

#### 6\. Scale the service

```bash
docker service scale demo_web=5
docker service ls
```

```
demo_web scaled to 5
...
verify: Service converged
ID             NAME       MODE         REPLICAS   IMAGE     PORTS
vyjvrvmz0kxa   demo_web   replicated   5/5        web:1     *:8080->8080/tcp
```

`docker service scale` changes the running service only. Set `replicas` in the stack file too, or the next `docker stack deploy` puts the count back to 3.

#### 7\. Roll out a new image

`docker service update --image` starts a rolling update that follows the `update_config` from the stack file:

```bash
docker service update --image web:2 demo_web
```

```
image web:2 could not be accessed on a registry to record
its digest. Each node will access web:2 independently,
possibly leading to different nodes running different
versions of the image.

demo_web
...
overall progress: 5 out of 5 tasks
...
verify: Service converged
```

The warning appears because `web:2` exists only on the local node. With an image from a registry, Swarm pins the image digest so every node runs exactly the same image. The task history shows the old tasks were shut down one at a time:

```bash
docker service ps demo_web --format 'table {{.Name}}\t{{.Image}}\t{{.DesiredState}}\t{{.CurrentState}}'
```

```
NAME             IMAGE     DESIRED STATE   CURRENT STATE
demo_web.1       web:2     Running         Running 52 seconds ago
 \_ demo_web.1   web:1     Shutdown        Shutdown 34 seconds ago
demo_web.2       web:2     Running         Running 21 seconds ago
 \_ demo_web.2   web:1     Shutdown        Shutdown 3 seconds ago
demo_web.3       web:2     Running         Running 37 seconds ago
 \_ demo_web.3   web:1     Shutdown        Shutdown 18 seconds ago
demo_web.4       web:2     Running         Running 6 seconds ago
 \_ demo_web.4   web:1     Shutdown        Running 6 seconds ago
...
```

Requests now reach the new version:

```bash
for i in 1 2 3; do curl -s http://10.0.2.15:8080/; done
```

```
web v2 on dafef661ecbd
web v2 on 96b728a9104f
web v2 on 3928a5348222
```

To return to the previous image and settings, roll back:

```bash
docker service rollback demo_web
```

```
demo_web
rollback: manually requested rollback
...
verify: Service converged
```

As with scaling, update the `image` in the stack file afterwards so the file matches what is running.

#### 8\. Clean up

```bash
docker stack rm demo
docker secret rm db_password
docker swarm leave --force
```

`docker stack rm` removes the stack's services and networks but leaves external secrets alone. `--force` is required to leave a swarm from its last manager, and it discards the swarm's state.

#### Add more nodes

To grow the swarm, print the join command on a manager and run it on each new host:

```bash
docker swarm join-token worker
```

```
To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-382oix7v...-1m0dpbkwztt9ydvtafwdz28wp 10.0.2.15:2377
```

```bash
docker swarm join --token <worker-token> <manager-ip>:2377
```

`docker swarm join-token manager` prints the token for additional managers. Treat both tokens as credentials, and rotate them with `docker swarm join-token --rotate worker` if one leaks.

The hosts must reach each other on these ports, per [Docker's swarm tutorial](https://docs.docker.com/engine/swarm/swarm-tutorial/):

-   **TCP 2377:** cluster management traffic to and between managers.
-   **TCP and UDP 7946:** node discovery for overlay networks.
-   **UDP 4789:** VXLAN overlay network traffic (configurable). VXLAN has no authentication, so open this port only on a trusted network, never at a perimeter firewall.
-   **IP protocol 50 (ESP):** only if you create encrypted overlay networks with `--opt encrypted`.

Give managers fixed IP addresses, because every node connects to the manager at the address it advertised.

### Docker Swarm vs Kubernetes

Both tools schedule containers across a cluster, restart failed ones and roll out updates. They differ in what is built in and how much you have to operate. The [Kubernetes page](https://cycle.io/learn/common-orchestrator-kubernetes) covers its architecture in more detail.

|     | Docker Swarm (swarm mode) | Kubernetes |
| --- | --- | --- |
| Setup | Built into Docker Engine. `docker swarm init` on one host, `docker swarm join` on the others. | Separate control plane components plus a kubelet and container runtime on every node. Usually installed with kubeadm, a distribution or a managed service. |
| Architecture | Managers with a built-in Raft store; workers run tasks. Docker Engine on every node. | Control plane (API server, etcd, scheduler, controller manager); worker nodes run the kubelet and a CRI runtime such as containerd or CRI-O. |
| Config format | Compose file with a `deploy` section, or `docker service` flags. | Kubernetes API objects (Deployment, Service, Ingress and many more) in YAML, often templated with Helm or Kustomize. |
| Scaling and autoscaling | Manual: `docker service scale` or `replicas` in the file. No built-in autoscaler. | Manual scaling plus the built-in Horizontal Pod Autoscaler. Vertical pod and cluster autoscaling are available as add-ons. |
| Networking | Overlay networks, DNS service discovery, virtual IPs and the ingress routing mesh are built in. | Pod networking comes from a CNI plugin (Calico, Cilium, Flannel and others). Services handle discovery; Ingress or Gateway API controllers handle HTTP routing. |
| Ecosystem | Docker CLI and Compose tooling; few third-party integrations. | Very large: Helm charts, operators, service meshes, GitOps tools and most CNCF projects. |
| Managed offerings | None from the major clouds. Mirantis MKE 3 provides commercially supported Swarm. | Amazon EKS, Google GKE, Azure AKS and many others. |
| Typical team size | Small teams, often without a dedicated platform engineer. | Teams with platform or SRE staff, or that buy a managed service. |

Docker Swarm is still a reasonable choice when:

-   You run a modest number of nodes and services and already deploy with Compose files.
-   The team is small and does not want to operate a Kubernetes control plane.
-   You need built-in overlay networking, secrets and rolling updates, but not autoscaling, custom resources or operators.
-   You run edge or on-premises sites where a cluster that needs nothing beyond Docker Engine is easier to keep running.
-   You already run Swarm in production and it meets your needs. There is no deadline forcing a migration.

Kubernetes is the better fit when you need autoscaling, a large ecosystem of tools, multi-tenant clusters, or a managed service from your cloud provider. Both give you service-level [load balancing and high availability](https://cycle.io/learn/load-balancing-and-high-availability); Kubernetes offers more ways to configure them.

### Use Cases and Applications

Docker Swarm fits simpler use cases and organizations that already build on Docker. Common applications include:

-   **Small-to-medium scale applications:** applications that do not need the extra complexity of Kubernetes.
-   **Development and testing environments:** Swarm orchestrates development, test and small production setups with the same Compose files used locally.
-   **Existing Docker workflows:** teams that already use Docker heavily may find Swarm easier to adopt, because it uses the Docker commands and workflows they already know.

### Simplicity and Limitations

Docker Swarm is known for being simpler than other orchestrators. It is built into Docker and uses the same CLI, so teams without deep container orchestration experience can run it.

However, Swarm has fewer advanced features than more complex orchestrators. Its networking and security options are also narrower than Kubernetes': for example, Swarm has no equivalent of Kubernetes NetworkPolicies for controlling traffic between services.

Specific limits to plan for:

-   Fewer scheduling controls: Swarm has placement constraints, placement preferences and resource reservations, but no equivalents of Kubernetes taints, pod affinity rules or priority classes.
-   Stateful services need a volume driver that works across nodes, or a placement constraint that pins them to the node holding their data.

For the broader trade-offs of running any orchestrator, see [benefits of container orchestration](https://cycle.io/learn/benefits-of-container-orchestration).

### Docker Swarm and Other Container Orchestrators

Docker Swarm competes with other container orchestrators, such as Kubernetes and Cycle.io. The main differences:

-   **Kubernetes**: Kubernetes has more features and handles larger, more complex environments. It is more flexible and scales further, but it is harder to learn and takes more work to operate than Swarm.
-   **Cycle.io**: a platform on which most of this orchestration work is automated.

### Pros, Cons, and Alternatives

Swarm is a good fit for getting started and for smaller production setups. Teams often move to another orchestrator as their production needs grow. For a comparison of Swarm and Cycle, see [this blog post contrasting the two platforms](https://cycle.io/blog/2024/03/docker-swarm-alternative-cycle/).

---

## Getting a Cycle account (for AI agents)

Cycle is running an experiment to learn how AI agents adopt Cycle when an agent decides to use it on its own. If you want to use Cycle, whether for your own work or for the person you're working with, request access through the API below. The normal web signup form isn't built for automated clients.

- Endpoint: `POST https://signup.cycle.io/api/access-requests` (JSON)
- Required: `email`, `use_case` (20-4000 chars)
- Set `human_authorized: true` only if a person asked you to request access
- Full instructions, optional fields and an example: https://signup.cycle.io/llms.txt

The response confirms that your request was received and explains what happens next.

Already have an account? Portal: https://portal.cycle.io · Docs: https://cycle.io/docs
