Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 38 ยท Getting Started

What Is Docker Swarm?

Learn what Docker Swarm mode is, what problems an orchestrator solves, which features it offers, and how the rest of this tutorial is organized.

A single Docker host is great for development: you run docker run, the container starts, and you move on. Production is different. One machine can fail, one container can crash at 3 a.m., and one host eventually runs out of memory. You need several machines, several copies of each program, and something that keeps them all healthy without a human typing commands.

Docker Swarm (officially "swarm mode") is the orchestrator built into the Docker Engine. It turns a group of Docker hosts into one logical cluster. You describe what you want ("run five copies of this web image, reachable on port 80"), and Swarm continuously works to make the real world match that description.

Honest note about this tutorial. A Swarm cluster needs several Docker daemons, and the site cannot run a Docker daemon in your browser. So the commands in this course are shown as read-only console blocks, and we only print output when its shape is certain (we use placeholders such as <node-id> for values that differ on every machine). Where you see a runnable editor, it is a clearly labelled stand-in written in Python: a small simulator or calculator that teaches the same idea (quorum math, task scheduling, load balancing) so you can experiment with it. Try the real commands on your own machines or in the practice setup from lesson 3.

The problem an orchestrator solves

Imagine you run an online shop with a web front end, an API and a worker. Without an orchestrator you must:

  • decide by hand which machine runs which container,
  • restart containers that crash,
  • move containers when a machine dies,
  • connect containers on different machines to each other,
  • roll out new versions without downtime,
  • store passwords somewhere safer than an environment variable in a shell history.

An orchestrator automates exactly these jobs. Swarm's answer to each is a built-in feature:

What Swarm does for you

Scheduling Picks a node for every container
Self-healing Replaces failed containers
Networking Overlay networks and load balancing
Rolling updates New versions with no downtime

All of it ships inside the Docker Engine.

1 / 2

Vocabulary you will use all course long

Term Meaning
Node One Docker Engine that has joined the swarm (a VM, a bare-metal server, a Raspberry Pi).
Manager node Accepts your commands, stores the cluster state, schedules work.
Worker node Only runs the containers that managers assign to it.
Service The desired state: an image, a number of replicas, ports, limits.
Task One scheduled container that belongs to a service.
Stack A group of services deployed together from a Compose file.

You will meet each of these in depth. For now, remember the chain: you create a service, Swarm turns it into tasks, and each task runs one container on some node.

flowchart LR
  U["You: docker service create"] --> M["Manager: stores desired state"]
  M --> S["Scheduler"]
  S --> T1["Task 1 on node A"]
  S --> T2["Task 2 on node B"]
  S --> T3["Task 3 on node C"]

The manager turns a service definition into tasks and places them on nodes.

Desired state and reconciliation

The most important idea in Swarm is declarative desired state. You do not say "start a container". You say "there must be three replicas of web". If one dies, the number is two, the real state no longer matches, and Swarm starts a replacement. This loop of compare and fix runs all the time. Here is a tiny stand-in that shows the loop. It is not Swarm code, only the idea.

Python Stand-in: a reconciliation loop

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

What Swarm is not

Swarm is deliberately small. It does not build images, does not give you a graphical dashboard, and does not have the huge ecosystem of Kubernetes (operators, custom resources, service meshes). Its strength is that if you already know Docker, you are productive in an afternoon. Lesson 2 compares the three tools honestly.

How this course is organized

  1. Getting Started: what Swarm is, setting up nodes, your first service.
  2. Swarm Architecture: managers, Raft, node management, security.
  3. Services and Tasks: every option of a service and how tasks behave.
  4. Networking and Overlay: how containers on different machines talk.
  5. to 9. Secrets, stacks, scaling and updates, operations, and projects.

Prior knowledge: you should be comfortable with docker run, images and volumes. If not, start with the Docker tutorial.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. What best describes Docker Swarm?

    Swarm mode groups Docker hosts into one cluster and keeps the desired number of containers running.
  2. 2. What is a task in Swarm?

    A service describes the desired state; each of its replicas is a task that runs one container on some node.
  3. 3. You declare three replicas and one container crashes. What does Swarm do?

    Swarm compares the desired state with the actual state and schedules a new task to close the gap.

Summary

  • Swarm mode is the orchestrator inside the Docker Engine.
  • You describe desired state; Swarm reconciles reality to match it.
  • Nodes are managers or workers; services become tasks that run containers.
  • Runnable editors in this course are labelled Python stand-ins, because no Docker daemon runs on the site.

Next: Swarm, Compose and Kubernetes