Docker Swarm Basics (Managers, Workers, Services & Stacks)
Deploy Swarm services and stacks across manager and worker nodes.
In plain words
Use Swarm for a small Docker-native multi-node cluster with service reconciliation and routing mesh, while accepting its control-plane and storage boundaries.
Think of it like…
Managers are the shift-control office, workers are production floors, services are job descriptions and tasks are workers currently carrying them out.
Where you’ve seen it
In practice, docker swarm init --advertise-addr 10.0.0.10; docker service create --replicas=3 --publish 8080:80 --name api api:2.1 is the concrete move for this job: deploy Swarm services and stacks across manager and worker nodes. The release is not accepted until docker node ls, docker service ps api and drain one worker while observing task rescheduling and quorum confirms the result.
Words you’ll hear
- Managers
- The implementation control in
docker swarm init --advertise-addr 10.0.0.10; docker service create --replicas=3 --publish 8080:80 --name api api:2.1for deploy Swarm services and stacks across manager and worker nodes. - Workers
- The result to observe with
docker node ls, docker service ps api and drain one worker while observing task rescheduling and quorum, rather than infer from a successful command alone. - Services
- The production boundary exposed when running three replicas with all state on one local named volume, or converting workers to managers until an even-number quorum becomes fragile.
Visual diagram
Theory & deep dive
Managers control path
The concrete mechanism is docker swarm init --advertise-addr 10.0.0.10; docker service create --replicas=3 --publish 8080:80 --name api api:2.1. The observable result is docker node ls, docker service ps api and drain one worker while observing task rescheduling and quorum; if those disagree, inspect the runtime evidence before changing unrelated settings.
Deploy Swarm services and stacks across manager and worker nodes. Keep Managers, Workers and Services in the same deployment record so the intent and the observed state cannot drift apart.
docker swarm init --advertise-addr 10.0.0.10; docker service create --replicas=3 --publish 8080:80 --name api api:2.1
docker node ls, docker service ps api and drain one worker while observing task rescheduling and quorum, not with command success alone.Services failure boundary
A manager quorum is not every manager: losing quorum stops cluster mutations even if running tasks continue. Swarm is not a distributed database and cannot turn local volumes into portable data. The narrow failure to design for is running three replicas with all state on one local named volume, or converting workers to managers until an even-number quorum becomes fragile.
Accept this compromise explicitly: Swarm is easy for Docker users; Kubernetes has broader ecosystem and declarative APIs but a larger operational surface. The controlled check-docker node ls, docker service ps api and drain one worker while observing task rescheduling and quorum-also identifies the point where a different design is safer.
Exercise this failure safely: running three replicas with all state on one local named volume, or converting workers to managers until an even-number quorum becomes fragile.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: A manager quorum is not every manager: losing quorum stops cluster mutations even if running tasks continue. Swarm is not a distributed database and cannot turn local volumes into portable data.
- Intent
- Managers
When to use it & trade-offs
What it is
A Swarm has manager nodes holding Raft-backed cluster state and worker nodes running tasks. Services define desired replica/placement/update state, tasks are container instances, and stacks apply Compose-like multiple-service declarations.
Why it matters: A manager quorum is not every manager: losing quorum stops cluster mutations even if running tasks continue. Swarm is not a distributed database and cannot turn local volumes into portable data.
When to reach for it
- The fit is strongest for this job: deploy Swarm services and stacks across manager and worker nodes. Pair it with
docker node ls, docker service ps api and drain one worker while observing task rescheduling and quorumin the runbook. - Production Managers changes should make Workers observable through
docker swarm init --advertise-addr 10.0.0.10; docker service create --replicas=3 --publish 8080:80 --name api api:2.1, rather than trusting the runtime default. - Keep a rollback example for the case where running three replicas with all state on one local named volume, or converting workers to managers until an even-number quorum becomes fragile.
When to avoid or be careful
- Do not accept command success while the system can still fail by running three replicas with all state on one local named volume, or converting workers to managers until an even-number quorum becomes fragile.
- Avoid erasing Services protection merely to dodge this cost: “Swarm is easy for Docker users; Kubernetes has broader ecosystem and declarative APIs but a larger operational surface”.
- Do not replace the evidence path-
docker node ls, docker service ps api and drain one worker while observing task rescheduling and quorum-with a screenshot or a mutable tag.
docker swarm init --advertise-addr 10.0.0.10; docker service create --replicas=3 --publish 8080:80 --name api api:2.1: practical choices
Strengths: A Swarm has manager nodes holding Raft-backed cluster state and worker nodes running tasks. Services define desired replica/placement/update state, tasks are container instances, and stacks apply Compose-like multiple-service declarations.
Watch out: Swarm is easy for Docker users; Kubernetes has broader ecosystem and declarative APIs but a larger operational surface.
Strengths: It can begin with docker swarm init --advertise-addr 10.0.0.10; docker service create --replicas=3 --publish 8080:80 --name api api:2.1 and fewer surrounding controls.
Watch out: It silently accepts running three replicas with all state on one local named volume, or converting workers to managers until an even-number quorum becomes fragile, which makes the result hard to reproduce after promotion.
Strengths: A manager quorum is not every manager: losing quorum stops cluster mutations even if running tasks continue. Swarm is not a distributed database and cannot turn local volumes into portable data.
Watch out: The platform adds an ownership and debugging layer; retain docker node ls, docker service ps api and drain one worker while observing task rescheduling and quorum as the direct check.
Interview signals & numbers to know
When this topic comes up
- docker swarm init --advertise-addr 10.0.0.10; docker service create --replicas=3 --publish 8080:80 --name api api:2.1
- docker node ls, docker service ps api and drain one worker while observing task rescheduling and quorum
- Failure signature: running three replicas with all state on one local named volume, or converting workers to managers until an even-number quorum becomes fragile
- Trade-off: Swarm is easy for Docker users; Kubernetes has broader ecosystem and declarative APIs but a larger operational surface.
Benchmarks & rules of thumb
- 3 managers
- minimum resilient quorum example
- 2/3
- quorum needed for a three-manager cluster
- 1 task/replica
- the scheduler attempts to maintain service convergence
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
docker swarm init --advertise-addr 10.0.0.10; docker service create --replicas=3 --publish 8080:80 --name api api:2.1as proof and skippingdocker node ls, docker service ps api and drain one worker while observing task rescheduling and quorum. - Running three replicas with all state on one local named volume, or converting workers to managers until an even-number quorum becomes fragile
- Optimizing Managers without accepting that swarm is easy for Docker users; Kubernetes has broader ecosystem and declarative APIs but a larger operational surface.
Likely interviewer follow-ups
- Why does
docker swarm init --advertise-addr 10.0.0.10; docker service create --replicas=3 --publish 8080:80 --name api api:2.1address Managers here rather than through application code? - How would you distinguish healthy Workers from the failure “running three replicas with all state on one local named volume, or converting workers to managers until an even-number quorum becomes fragile” using
docker node ls, docker service ps api and drain one worker while observing task rescheduling and quorum? - When would this trade-off-“Swarm is easy for Docker users; Kubernetes has broader ecosystem and declarative APIs but a larger operational surface”-justify a different Services design?
docker swarm init --advertise-addr 10.0.0.10; docker service create --replicas=3 --publish 8080:80 --name api api:2.1-and one proof-docker node ls, docker service ps api and drain one worker while observing task rescheduling and quorum. Then name the boundary: running three replicas with all state on one local named volume, or converting workers to managers until an even-number quorum becomes fragile.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Docker Swarm Basics (Managers, Workers, Services & Stacks) with generative AI interview Q&A and hands-on practice.