Lesson content
Read, practise, then check your understanding
Advanced Topics: Swarm and Kubernetes Integration
A single Docker daemon manages one host. Orchestrators add desired state, scheduling, service discovery, rolling updates, health management, secrets, and multi-host networking. Docker Swarm is built into Docker Engine; Kubernetes is a broader orchestration platform that commonly consumes OCI-compatible images built with Docker.
Core ideas
- A Swarm service declares an image, replicas, networks, update policy, and placement constraints.
- A stack deploys a related group of Swarm services from a Compose-style specification.
- Kubernetes uses resources such as Deployments, Services, ConfigMaps, Secrets, Jobs, and StatefulSets.
- Kubernetes nodes use a CRI-compatible runtime such as containerd; Docker-built OCI images remain portable.
How it works
Build once, publish to a registry, and promote the same image digest across environments. The orchestrator should own restart, rollout, placement, and configuration. Add readiness and liveness signals that reflect actual behavior, define resource requests and limits, and plan stateful storage independently.
Command or configuration example
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
spec:
replicas: 3
selector:
matchLabels: { app: api }
template:
metadata:
labels: { app: api }
spec:
containers:
- name: api
image: registry.example.com/api@sha256:REPLACE_WITH_DIGEST
ports: [{ containerPort: 8080 }]
resources:
requests: { cpu: 100m, memory: 128Mi }
limits: { memory: 256Mi }
Run examples first in a disposable environment. Replace image names, versions, credentials, ports, paths, and resource values with reviewed settings appropriate to your system.
Production guidance
- Do not treat Compose, Swarm, and Kubernetes files as interchangeable despite overlapping concepts.
- Use declarative delivery, immutable image digests, rollout health, and a tested rollback strategy.
- Secure the registry, orchestrator API, node runtime, workload identity, network paths, and secret distribution.
The chapter quiz follows this lesson and checks the concepts as well as the operational tradeoffs.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.