Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 38 ยท Getting Started

Swarm, Compose and Kubernetes

Compare Docker Swarm with Docker Compose and Kubernetes: scope, features, complexity and a simple decision guide for choosing an orchestrator.

Three names come up whenever people talk about running containers: Docker Compose, Docker Swarm and Kubernetes. They overlap, which confuses beginners. This lesson places each tool on a map so that you know what Swarm is good for and when another tool is the better choice.

The short version: Compose describes a multi-container app on one host. Swarm runs it across several hosts using the same Docker tools. Kubernetes is a much larger platform for the same job with many more moving parts.

Docker Compose: one host

Compose reads a compose.yaml file and starts all the services on a single Docker Engine. It is perfect for local development and small single-server deployments.

CONSOLE
$ docker compose up -d

If that one machine dies, everything dies. Compose does not move containers elsewhere, and it does not spread replicas over machines.

Docker Swarm: a cluster with Docker's own tools

Swarm uses the same images, the same volumes concept and nearly the same Compose file format, but it spreads work over a cluster. The deploy command is docker stack deploy, and the file's deploy: section (replicas, update policy, placement) is used only by Swarm. You will study this in Stacks and Deployment.

CONSOLE
$ docker stack deploy -c compose.yaml shop

Strengths: tiny learning curve, one binary, secure by default (mutual TLS, encrypted secrets), a built-in routing mesh and rolling updates.

Kubernetes: a platform

Kubernetes (K8s) came from a different heritage. It has its own objects (Pod, Deployment, Service, Ingress, ConfigMap, StatefulSet and many more), its own CLI (kubectl), its own networking plug-ins and a huge ecosystem. It scales further and is more flexible, and every large cloud sells it as a managed service. The price is complexity: you assemble many pieces and learn many concepts.

Side by side

Question Compose Swarm Kubernetes
Hosts 1 Many Many
Setup Nothing extra docker swarm init Install a distribution or use a managed one
Config format Compose file Compose file (v3 style) + deploy: YAML manifests, Helm charts
Self-healing Restart policy only Yes, reschedules on other nodes Yes
Rolling updates No Built in Built in
Built-in load balancing No Routing mesh + VIPs Services + Ingress controllers
Autoscaling No No (you scale by hand or script) Yes (HPA, VPA, cluster autoscaler)
Ecosystem Small Small Very large
Typical team Developers Small teams, edge, simple production Platform teams, large systems
flowchart LR
  A["One host, dev"] --> B["Compose"]
  C["A few hosts, simple ops"] --> D["Swarm"]
  E["Many teams, complex platform"] --> F["Kubernetes"]

A rough fit by size and complexity, not a strict rule.

A fair look at Swarm's status

Docker maintains Swarm mode as part of the Engine, and it keeps working. Its development is slow compared with Kubernetes, and fewer third-party tools target it. That is a reasonable trade for some teams: fewer features also means fewer things to break and to learn. Before committing, check the current Docker documentation for the status of Swarm in your Docker version.

Choosing: a decision helper

Here is a deliberately simple checklist, written as a stand-in in Python. Change the answers and see how the advice changes. It is not an official tool, only a way to practice thinking about the trade-offs.

Python Stand-in: which tool fits?

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.

Moving between them

Because Swarm stacks use Compose files, the first step of "graduating" from Compose to Swarm is small: docker swarm init, then docker stack deploy. Moving from Swarm to Kubernetes later is a real migration (different objects, networking and storage), so choose with some care, but remember that your container images work everywhere. The skill you gain in image building, health checks and configuration through the environment transfers directly.

A second stand-in: a feature checklist

This one counts how many of your needs each tool covers out of the box. Edit the needs list.

Python Stand-in: feature coverage

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.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. Which tool runs a multi-container app on exactly one Docker host?

    Compose is single-host. Swarm and Kubernetes spread work across multiple hosts.
  2. 2. Which section of a Compose file is used only by Swarm when deploying a stack?

    The deploy key holds replicas, update policy and placement, and is read by docker stack deploy.
  3. 3. A strong reason to choose Swarm over Kubernetes is:

    Swarm reuses Docker's CLI and Compose files, so there is little new to learn.

Summary

  • Compose is one host, Swarm is a Docker-native cluster, Kubernetes is a larger platform.
  • Swarm trades features and ecosystem for simplicity.
  • Stacks reuse Compose files, so the first step up is small.
  • Pick by team skills and needs, not by fashion.

Next: Setting Up a Practice Cluster