Docker Swarm Tutorial
Learn Docker Swarm step by step: 38 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
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.
- Swarm, Compose and Kubernetes Compare Docker Swarm with Docker Compose and Kubernetes: scope, features, complexity and a simple decision guide for choosing an orchestrator.
- Setting Up a Practice Cluster Prepare machines for Docker Swarm: install Docker, choose between virtual machines and Docker-in-Docker, open the required ports and plan the node layout.
- swarm init and join Create a swarm with docker swarm init, add workers and managers with join tokens, choose the advertise address and leave or reset a cluster safely.
- Your First Swarm Service Create, inspect, scale and remove your first Docker Swarm service with docker service commands, and watch tasks spread across the nodes of your cluster.
Swarm Architecture
- Managers and Workers Understand the two node roles in Docker Swarm, what managers do, the leader, how workers behave, and how to size and place manager nodes.
- Raft Consensus and Quorum Learn how Docker Swarm managers use the Raft algorithm to agree on cluster state, what quorum means, and how to recover when too many managers fail.
- Node Management Manage Docker Swarm nodes: list and inspect them, drain for maintenance, pause scheduling, promote and demote, add labels and remove nodes safely.
- Swarm Security and PKI See how Docker Swarm secures a cluster by default: the built-in certificate authority, mutual TLS, certificate rotation, join tokens and autolock.
- The Orchestrator and Reconciliation See the internal components of a Swarm manager (orchestrator, allocator, scheduler, dispatcher) and how the reconciliation loop turns services into running tasks.
Services and Tasks
- Service Create Options A guided tour of docker service create: image, name, replicas, environment, mounts, networks, ports, update and restart flags, and how to inspect the result.
- Replicated and Global Services Understand the two Swarm service modes: replicated services with a fixed count and global services with one task per node, plus when to use each.
- The Task Lifecycle Follow a Swarm task from new to running to shutdown: every task state, what desired state means, how to read docker service ps and why failed tasks pile up.
- Placement Constraints and Preferences Control where Swarm runs tasks with placement constraints, spread preferences and max replicas per node, using node attributes and labels.
- Resource Limits and Reservations Set CPU and memory limits and reservations on Swarm services, understand how the scheduler uses reservations and what happens when a container exceeds its limit.
- Health Checks and Restart Policies Teach Swarm to detect broken containers with health checks, control restarts with restart conditions, delays and windows, and avoid crash loops.
Networking and Overlay
- Overlay Networks Learn how overlay networks connect containers across Swarm nodes with VXLAN, how to create, attach and encrypt them, and how ingress and docker_gwbridge fit in.
- Service Discovery and VIPs Understand how containers find each other in Swarm: the embedded DNS server, virtual IPs, load balancing with IPVS, tasks.servicename and DNS round-robin.
- The Routing Mesh and Published Ports Learn how the Swarm ingress routing mesh exposes a service on every node, how host mode differs, and how to front it with a load balancer and keep client IPs.
- Network Troubleshooting and Tuning A practical guide to debugging Swarm networking: DNS, VIPs, ports, MTU, subnet clashes, ingress, stale entries, plus tuning knobs for the data path.
Secrets and Configs
- Docker Swarm Secrets: Create and Use Them Learn what Swarm secrets are, how docker secret create works, how services read them from /run/secrets, and why secrets beat environment variables for passwords.
- Rotating Secrets and Configs in Docker Swarm Use docker config for non-sensitive files, and learn the safe rotate pattern for immutable secrets and configs: new name, service update, remove the old one.
- Protecting Swarm Secrets: Autolock and Hygiene Understand how Swarm encrypts Raft data, what autolock and the unlock key do, how to rotate keys, and a checklist for keeping secrets out of logs, images and Git.
Stacks and Deployment
- Compose Files for Docker Swarm Stacks Write a Compose file that docker stack deploy understands: services, networks, volumes, secrets and configs, which keys Swarm ignores, and how names are generated.
- The deploy Key: Replicas, Placement and Policies Master the deploy section of a stack file: replicated and global mode, placement constraints and preferences, restart policy, update_config, labels and endpoint_mode.
- Stack Commands, Environments and Overrides Learn every docker stack command, how variable substitution and multiple -c files give you dev, staging and production variants, and common deploy flags.
- Private Registries and Image Delivery in Swarm Deliver images to every Swarm node: docker login with --with-registry-auth, pinning digests, a registry service inside the swarm, pull failures and a release flow.
Scaling and Updates
- Scaling Services Up and Down in Docker Swarm Scale replicated services with docker service scale and update --replicas, understand how Swarm rebalances, what limits scaling, and how to plan node capacity.
- Rolling Updates in Docker Swarm Update Swarm services without downtime: parallelism, delay, start-first versus stop-first order, failure_action, monitor, and how to watch and tune a rollout.
- Health Checks and Rollbacks in Docker Swarm Add HEALTHCHECK or healthcheck settings so Swarm knows when a task is ready, learn how unhealthy tasks are replaced, and use docker service rollback safely.
- Resource Limits and Reservations in Docker Swarm Control CPU and memory for Swarm services: limits versus reservations, how the scheduler uses them, OOM kills, ulimits, and how to size a service from measurements.
Operations and Alternatives
- Monitoring and Logging a Docker Swarm See what is happening in a swarm: docker service logs, events, node and task states, logging drivers, a global log-agent pattern and metrics with Prometheus-style tools.
- Backup and Disaster Recovery for Docker Swarm Back up Swarm state from a manager, restore it, recover from lost quorum with --force-new-cluster, and protect volumes and data with a tested disaster plan.
- Docker Swarm vs Kubernetes and Other Options Compare Docker Swarm with Kubernetes, Nomad and plain Compose on a single host: concepts, features, operations cost, and a decision guide for teams of different sizes.
Projects and Practice
- Project: Deploy a Complete Web Stack on Swarm Build and deploy a three-tier stack on Docker Swarm: proxy, API and PostgreSQL with secrets, configs, health checks, placement and a validated stack file, step by step.
- Project: A Zero-Downtime Release Process Design a release process for Swarm: build once, deploy by tag, canary with a second service, watch health, roll back automatically, plus a runnable rollout simulator.
- Project: A Swarm Capacity Planner Build a runnable capacity planner that answers how many nodes a Swarm needs, what happens when a node fails, and where reservations are too high, then apply it to real stacks.
- Docker Swarm Practice Questions and Exercises Test your Swarm skills with scenario questions on secrets, stacks, updates, failures and recovery, hands-on exercises for a lab, and interview-style answers explained.