DEV Community

Yash Sonawane
Yash Sonawane

Posted on

Episode 18: Docker Swarm – Introduction to Orchestration

In previous episodes, we explored Docker Compose for managing multi-container applications. Now, it’s time to move into container orchestration — managing multiple containers across different machines. One of the first orchestration tools introduced by Docker itself is Docker Swarm.


🌐 What is Docker Swarm?

  • Docker Swarm is Docker’s native clustering and orchestration tool.
  • It allows you to create a cluster of Docker nodes and deploy services across them.
  • Provides high availability, scalability, and load balancing.

Think of it as a way to run containers not just on one machine but across many machines working together.


🛠️ Key Concepts

  1. Node → A machine participating in the swarm (can be physical or virtual).
  • Manager Node: Handles cluster management, scheduling, and orchestration.
  • Worker Node: Executes the tasks given by the manager.
  1. Service → Defines how containers (called tasks) should run in the swarm.

  2. Task → A running container assigned to a node.

  3. Overlay Network → Enables communication between containers running on different machines.


⚡ Setting Up Docker Swarm

  1. Initialize Swarm Mode on the first machine (manager):
docker swarm init --advertise-addr <MANAGER-IP>
Enter fullscreen mode Exit fullscreen mode
  1. Join Worker Nodes (command is shown after swarm init):
docker swarm join --token <WORKER-TOKEN> <MANAGER-IP>:2377
Enter fullscreen mode Exit fullscreen mode
  1. Verify Nodes in the Swarm:
docker node ls
Enter fullscreen mode Exit fullscreen mode

🚀 Deploying a Service in Swarm

Example: Running an nginx service with 3 replicas

docker service create --name my-nginx --replicas 3 -p 8080:80 nginx
Enter fullscreen mode Exit fullscreen mode

Check running services:

docker service ls
docker service ps my-nginx
Enter fullscreen mode Exit fullscreen mode

🔁 Scaling a Service

docker service scale my-nginx=5
Enter fullscreen mode Exit fullscreen mode

This will automatically balance containers across the nodes.


🛡️ Benefits of Docker Swarm

  • Easy setup and integration with Docker CLI.
  • Provides load balancing out of the box.
  • Ensures high availability — if a container fails, Swarm replaces it.
  • Secure by default (TLS encrypted communication).

🎯 When to Use Docker Swarm?

  • Small to medium production clusters.
  • When you need simpler orchestration than Kubernetes.
  • For teams already invested in Docker and looking for an easy scaling solution.

✅ In the next episode, we’ll dive into Docker Networking Deep Dive (Bridge, Host, Overlay, Macvlan) to understand how containers communicate in different environments.


⚡ Question for you: Do you want me to go deeper into Docker Swarm (advanced service deployments, secrets, configs) before we move to networking, or should we continue to networking next?

Top comments (0)