Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 143/ 160
08. Container Orchestration & Ecosystem

Docker Swarm Basics (Managers, Workers, Services & Stacks)

Deploy Swarm services and stacks across manager and worker nodes.

IntermediateManagers · Workers3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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.1 for 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

Loading interactive 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.

Concrete Managers setup

docker swarm init --advertise-addr 10.0.0.10; docker service create --replicas=3 --publish 8080:80 --name api api:2.1

Key takeaway: Prove Workers with 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.

Deliberate failure test

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.

Key takeaway: Swarm is easy for Docker users; Kubernetes has broader ecosystem and declarative APIs but a larger operational surface.

How it works, step by step

Step 1 of 4
Design

1. 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.

Use Swarm for a small Docker-native multi-node cluster with service reconciliation and routing mesh, while accepting its control-plane and storage boundaries.
Key numbers at this step
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 quorum in 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

Explicit Managers
Best for: Deploy Swarm services and stacks across manager and worker nodes, with a reviewed runbook.

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.

Ambient default
Best for: Short-lived Workers experiments with low blast radius.

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.

Managed Services
Best for: Teams that centralize Services policy across many workloads.

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.1 as proof and skipping docker 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.1 address 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?
Interview tip: Give one concrete operation-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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Orchestration Concepts (Scheduling, Self-Healing, Desired State)
Next topic
Routing Mesh & Overlay Networking in Docker Swarm