⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Docker & Containers Interview Questions Scenario 48 of 159 in Docker & Containers
Senior DevOps / SRE [L2] Docker Production Scenario [L2]
🎯 Target Role / Context: Docker Scenario #48 (L2) · Docker

Q: What is Docker Swarm and how does it compare to Kubernetes?

Docker Swarm is Docker Engine's built-in clustering and orchestration mode: you join several hosts into one swarm, declare services, and Swarm schedules, load-balances and restarts the containers.

#Docker #L2 #Containers #Linux #Ingress
🎙️ Candidate Opening & Architectural Context
"<strong>Docker Swarm</strong> is Docker Engine's built-in clustering and orchestration mode: you join several hosts into one swarm, declare services, and Swarm schedules, load-balances and restarts the containers. Compared with Kubernetes it is much simpler to set up and uses the familiar Docker CLI and Compose files, but it has a smaller feature set and ecosystem. Interviewers ask this to check that you can compare orchestrators on facts such as scheduling, networking, extensibility and operations, rather than repeating that Kubernetes has won."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's Docker Certified Associate (DCA) Hands-On Lab Course covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: <strong>Docker Swarm</strong> is Docker Engine's built-in clustering and orchestration mode: you join several hosts into one swarm, declare services, and Swarm schedules, load-balances and restarts the containers. Compared with Kubernetes it is much simpler to set up and uses the familiar Docker CLI and Compose files, but it has a smaller feature set and ecosystem. Interviewers ask this to check that you can compare orchestrators on facts such as scheduling, networking, extensibility and operations, rather than repeating that Kubernetes has won.

1️⃣

Mental model: what Docker Swarm actually is

Swarm mode is a feature of the Docker daemon, not a separate product to install.

  • Managers and workers: Manager nodes hold cluster state in a Raft log and schedule tasks; worker nodes only run tasks. Use 3 or 5 managers (an odd number) for quorum.
  • Service and task: A service is the desired state (image, replicas, ports); each replica is a task that runs in one container on one node.
  • Overlay networking and routing mesh: Overlay networks span nodes, and published ports are reachable on every node through the ingress routing mesh.
  • Built-in secrets: docker secret stores encrypted data in the Raft log and mounts it as files under /run/secrets in the container.
  • Scheduling: The default strategy spreads tasks across nodes by load; you steer it with placement constraints such as node.labels.disk==ssd and preferences, but there is no equivalent of Kubernetes affinity, taints or priority classes.
Pro Tip: Swarm needs TCP 2377 (management), TCP and UDP 7946 (node gossip) and UDP 4789 (overlay VXLAN) open between nodes.
2️⃣

Hands-on: Docker Swarm cluster, service and stack

Create a cluster, deploy a replicated service and then a stack from a Compose file.

docker swarm init --advertise-addr 10.0.0.10
docker node ls
docker service create --name web --replicas 3 -p 80:80 nginx:1.27
docker service ls
docker service ps web          # which node runs which task

# compose.yaml (stack)
# services:
#   web:
#     image: nginx:1.27
#     ports: ["80:80"]
#     deploy:
#       replicas: 3
#       update_config: {parallelism: 1, delay: 10s, order: start-first}
docker stack deploy -c compose.yaml mystack
  • Initialise: docker swarm init --advertise-addr <manager-ip> prints a join token for workers.
  • Join nodes: Run the printed docker swarm join command on each worker, then check docker node ls.
  • Create a service: docker service create --replicas 3 -p 80:80 nginx:1.27 schedules three tasks across the nodes.
  • Deploy a stack: docker stack deploy -c compose.yaml mystack uses the Compose file format with a deploy: section for replicas and update policy.
  • Day-two commands: docker service update --image nginx:1.27.1 web performs a rolling update, docker service logs web aggregates task logs, and docker node update --availability drain <node> evacuates a node for maintenance.
Advertisement
3️⃣

Docker Swarm vs Kubernetes: the real differences

Compare on capabilities that matter in operations rather than popularity.

  • Setup: Swarm is one command per node. Kubernetes needs a control plane, a CNI plugin, an ingress controller and usually a managed service.
  • Scaling and autoscaling: Swarm scales manually with docker service scale; Kubernetes has HPA, VPA and cluster autoscalers.
  • Extensibility: Kubernetes has CRDs, operators, admission webhooks, RBAC and NetworkPolicy. Swarm has no equivalent extension model.
  • Rollouts: Swarm supports rolling updates and rollback via docker service update --rollback; Kubernetes adds probes-driven rollouts and progressive delivery tooling.
  • Ecosystem: Managed offerings, Helm charts, and vendor support target Kubernetes almost exclusively. Networking model: Swarm gives each service a virtual IP with built-in DNS load balancing; Kubernetes separates Service, Ingress or Gateway API and NetworkPolicy, which is more flexible but more to learn.
4️⃣

Operational caveats and failure modes

Know the places Swarm bites in production.

docker node ls                                   # managers show Leader / Reachable
docker node update --availability drain worker-2  # evacuate before maintenance
docker service update --rollback web              # revert last service update
docker service inspect --pretty web | grep -A3 UpdateConfig
# Last resort on a surviving manager after quorum loss:
docker swarm init --force-new-cluster --advertise-addr 10.0.0.10
  • Quorum loss: If a majority of managers fail, you cannot change cluster state until quorum returns; recover with docker swarm init --force-new-cluster on a surviving manager only as a last resort.
  • Routing mesh surprises: Client source IPs are NATed unless you use host-mode publishing; this affects logging and allow-lists.
  • Health checks: Define HEALTHCHECK or a service health check; otherwise a running but hung process counts as healthy.
  • Stateful data: Volumes are local to a node by default, so pin stateful tasks with placement constraints or use a volume plugin.
  • Upgrades: Upgrade managers one at a time and confirm docker node ls shows them Reachable before touching the next one, otherwise you risk losing quorum during the upgrade.
5️⃣

When to use which

The decision is mostly about team size, features required and ecosystem.

  • Choose Swarm: A small team, a handful of stateless services, existing Compose files, and no need for operators or autoscaling.
  • Choose Kubernetes: Multi-team platforms, autoscaling, policy and multi-tenancy, or any dependency on cloud-native tooling.
  • Migration path: Compose files can be converted as a starting point (for example with Kompose), but expect to rewrite networking and secrets.
  • Check support status: Swarm mode ships with Docker Engine, but confirm current maintenance and roadmap before betting a new platform on it.
  • Observability: Both work with Prometheus and Grafana, but Kubernetes has far more ready-made exporters, dashboards and operators; account for that when estimating effort.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Frame the answer as simplicity versus extensibility: Swarm gives you orchestration with the Docker CLI in minutes, while Kubernetes pays an operational cost to get autoscaling, policy and an operator ecosystem."
⚡ 60-Second Elevator Pitch Talking Points
  • Docker Swarm is Docker Engine's native clustering mode where managers keep Raft state and schedule replicated services across workers.
  • I verify with docker node ls, docker service ps and checking that three or five managers keep quorum and the required ports are open.
  • I automate with stack files in Git and rolling update settings, and I would pick Kubernetes once autoscaling, policy or operators are required.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Running two managers Raft needs a majority, so two managers tolerate zero failures; use three or five.
  2. Opening the Docker API on TCP without TLS It gives root-equivalent control of the host to anyone who can reach it.
  3. Assuming volumes follow tasks between nodes Local volumes stay on one node, so a rescheduled task starts with empty data.
  4. Declaring Swarm dead or Kubernetes always better The correct answer depends on scale, team skills and required features.
Advertisement
Want more Docker & Containers scenarios?
Explore our complete collection of scenario-based Docker & Containers interview runbooks.
Browse All Docker & Containers Questions →