From point A to point B
Point A: with Docker and Compose you manage a complete application, but on a single host. If that server goes down, the application goes down; if more traffic arrives than it can handle, there is nowhere to grow. Point B: by the end of this chapter you will understand what an orchestrator solves, create a Docker Swarm cluster with a replicated service and recognize the pieces of Kubernetes, which is where the path continues.
Why you need an orchestrator
With docker run or Compose, you decide which host each container runs on and you keep an eye on it to make sure it stays alive. That stops working as soon as you go beyond one server:
- Availability: if the host fails, someone has to launch the containers again on another one.
- Scale: with more load you need more copies of the application, spread across several servers, and traffic balanced between them.
- Updates: changing versions without cutting service means replacing the copies a few at a time.
An orchestrator automates all of that. You declare the state you want, for example "three copies of this image, published on port 8080", and the orchestrator spreads the containers across the cluster's nodes, watches them and replaces them when they fail.
Courses from a few years ago listed three options: Docker Swarm, Kubernetes and Apache Mesos. Mesos was retired and moved to the Apache Software Foundation Attic in October 2025. Today the conversation is Swarm or, above all, Kubernetes.
Docker Swarm: the orchestrator built into Docker
Swarm comes included in Docker Engine: you install nothing else. A Swarm cluster has two types of node:
- Managers: they keep the cluster state and decide where each container runs. For high availability you use three or five, always an odd number.
- Workers: they run the containers the managers assign to them.
The unit of work is the service: the equivalent of a docker run, but with a number of replicas that Swarm maintains and spreads across the nodes.
A service with three replicas spread across the cluster; the published port answers on any node. Diagram: The House of Routing.
Creating a Swarm cluster and a replicated service
You need Docker installed on each server (three virtual machines are enough). On the one that will be the manager:
# On the manager: use its IP on the network the nodes share
docker swarm init --advertise-addr 192.168.1.10
# Swarm initialized ... To add a worker to this swarm, run the following command:
# docker swarm join --token SWMTKN-1-... 192.168.1.10:2377
Copy the docker swarm join command it returns and run it on each worker. Then, back on the manager:
docker node ls # the three nodes, one marked as Leader
# A service with three nginx replicas, published on 8080
docker service create --name web --replicas 3 -p 8080:80 nginx:stable
docker service ls
docker service ps web # which node each replica runs on
Now test it the way an orchestrator would:
# Scale: Swarm creates two more replicas and spreads them out
docker service scale web=5
# Update with no downtime: replaces the replicas one by one
docker service update --image nginx:alpine web
# Simulate a failure: shut down a worker and watch Swarm reschedule its replicas
docker service ps web
# Clean-up
docker service rm web
The published port answers on any node in the cluster, even one without a replica: Swarm's routing mesh forwards the request to an active container.
docker stack deploy -c compose.yaml my-app. With the deploy: key you set replicas, limits and update policies. From chapter 5 to a cluster is a short step.docker swarm join token lets nodes join your cluster. Treat it like a password; if it is exposed, rotate it with docker swarm join-token --rotate worker.Kubernetes: the industry standard
Kubernetes was born at Google, was donated to the Cloud Native Computing Foundation (CNCF) and today is the orchestrator every cloud offers: EKS on AWS, GKE on Google Cloud and AKS on Azure. It solves the same problems as Swarm, with far more room for configuration and extension.
The control plane decides; the nodes run the pods. Diagram: The House of Routing.
| Component | Where | What it does |
|---|---|---|
kube-apiserver | Control plane | The front door: everything, including kubectl, talks to it |
etcd | Control plane | Distributed key-value database holding the cluster state |
kube-scheduler | Control plane | Decides which node each pod runs on |
kube-controller-manager | Control plane | Compares the actual state with the desired one and fixes the differences |
kubelet | Every node | Agent that starts and watches the pods on its node |
| Container runtime | Every node | Runs the containers; today it is usually containerd |
kube-proxy | Every node | Implements Service networking |
The command-line tool is kubectl. The equivalent of the Swarm service you created above is a Deployment:
kubectl cluster-info
kubectl get nodes
kubectl create deployment web --image=nginx:stable --replicas=3
kubectl get pods -o wide # three pods spread across the nodes
kubectl scale deployment web --replicas=5
kubectl run no longer accepts --replicas: it creates a single pod. For replicas you use kubectl create deployment. And Kubernetes no longer runs containers with Docker: since version 1.24 it uses a CRI-compatible runtime directly, usually containerd. Your Docker images work just the same, because they follow the OCI standard.Swarm or Kubernetes
| Docker Swarm | Kubernetes | |
|---|---|---|
| Installation | Included in Docker Engine | Its own distribution or a managed cloud service |
| Learning curve | Low: reuses Docker and Compose concepts | High: many new objects and concepts |
| Scale and ecosystem | Small and medium clusters | Industry standard, with a huge ecosystem |
| In the cloud | You manage it | EKS, GKE, AKS and many more |
Swarm is a good option for small teams that want high availability without complexity. For a career in modern cloud, Kubernetes is essential, and that is why it is the next topic on the path.
Challenge
Answer before you open the solution. Getting it wrong here is the cheapest way to learn.
1. What problem does an orchestrator solve that Compose does not?
Running and watching containers on several hosts: spreading them out, replacing them if a node goes down, scaling them and updating them with no downtime.
2. Where do you run docker service create?
On a manager. Workers only run the tasks assigned to them.
3. A Swarm service publishes port 8080 with three replicas on a five-node cluster. Which nodes does the port answer on?
All five. The routing mesh forwards the request to an active replica even if the node has none.
4. Which Kubernetes component decides which node a new pod runs on?
kube-scheduler. Then the kubelet on that node starts it.
5. Kubernetes no longer uses Docker as its runtime. Do your images built with Docker stop working?
No. They are standard OCI images and containerd runs them just the same.
What you take away
- An orchestrator spreads, watches, scales and updates containers across several hosts.
- Swarm comes with Docker:
swarm init,swarm joinandservice create --replicas. - An odd number of managers for high availability; workers to run the containers.
- Kubernetes: control plane (API server, etcd, scheduler, controllers) and nodes (kubelet, runtime, kube-proxy).
- Replicas in Kubernetes with
kubectl create deployment --replicas. - Kubernetes uses containerd; your Docker images still work.
You have finished the ten chapters of Docker from Scratch. Before moving on to Kubernetes, the extra chapter gets you reading and writing YAML with confidence.
Official resources
- Swarm mode overviewdocs.docker.com
- Getting started with Swarm modedocs.docker.com
- Swarm routing meshdocs.docker.com
- Kubernetes componentskubernetes.io
- Dockershim removal FAQkubernetes.io
- Apache Mesos (Attic)attic.apache.org
Source and credits. Chapter written from Jesús Espinoza's study notes on KodeKloud's Docker for Absolute Beginners course (December 2024). Text drafted with AI assistance; original diagrams by The House of Routing. Technical details were checked against the official Docker documentation.