🐳 Creating a 3-Node Docker Swarm Cluster: A Simple & Fun Guide



This content originally appeared on DEV Community and was authored by SOVANNARO

If you’ve ever wanted to scale your Docker applications like a pro, then Docker Swarm is your gateway! In this guide, we’ll walk you through creating your own 3-node Docker Swarm cluster β€” one manager and two workers β€” all from scratch!

Whether you’re running this on local VMs or cloud instances, the steps are clear and beginner-friendly. So grab your terminal and let’s swarm! πŸš€

🧠 What is Docker Swarm?

Docker Swarm is a built-in orchestration tool that lets you manage a cluster of Docker nodes. Think of it like forming a superhero team of machines that can deploy and scale your app together.

There are two types of nodes in Swarm:

  • 🧠 Manager Node: The brain that controls and schedules tasks.
  • πŸ’ͺ Worker Nodes: The muscles that actually run the containers.

πŸ›  What You Need

  • 3 Linux machines (can be local VMs, cloud VMs, or even Raspberry Pis).
  • Docker installed on all 3 machines.
  • Network access between all nodes.
  • Basic terminal and SSH access.

Let’s name our nodes:

  • manager-node – the main control center.
  • worker-node-1 – the first worker.
  • worker-node-2 – the second worker.

βš™ Step-by-Step: Create the Swarm Cluster

1⃣ Install Docker (Skip if already installed)

On all 3 machines, run:

sudo apt update
sudo apt install docker.io -y
sudo systemctl enable docker
sudo systemctl start docker

You can verify Docker is working with:

docker --version

2⃣ Initialize the Swarm on Manager

SSH into the manager node, then run:

docker swarm init --advertise-addr <MANAGER-IP>

πŸ“Œ Replace <MANAGER-IP> with the manager’s IP address (you can use ip a to find it).

After running this, you’ll get a command that looks like this:

docker swarm join --token SWMTKN-1-xxxx <MANAGER-IP>:2377

Copy this! You’ll use it to join the worker nodes.

3⃣ Join Worker Nodes to the Swarm

Now SSH into each worker node, and run the command you copied:

docker swarm join --token SWMTKN-1-xxxx <MANAGER-IP>:2377

Each worker will respond with:

This node joined a swarm as a worker.

πŸŽ‰ Boom! You’re now running a swarm with 1 manager and 2 workers!

4⃣ Check the Cluster Status

Go back to the manager node and run:

docker node ls

You’ll see something like:

ID         HOSTNAME        STATUS   AVAILABILITY   MANAGER STATUS
abcd1234   manager-node     Ready    Active         Leader
efgh5678   worker-node-1    Ready    Active         
ijkl9012   worker-node-2    Ready    Active         

That’s your healthy 3-node Swarm cluster. βœ…

πŸš€ Bonus: Deploy a Test Service

Let’s create a simple Nginx service across all nodes:

docker service create \
  --name web \
  --replicas 3 \
  -p 8080:80 \
  nginx

This will:

  • Deploy 3 replicas of Nginx.
  • Load-balance traffic to port 8080 across your nodes.

You can check the service status:

docker service ls
docker service ps web

Try accessing http://<any-node-ip>:8080 in your browser β€” Nginx should greet you! πŸŽ‰

🧹 Cleanup (Optional)

To leave the swarm:

  • On workers:
  docker swarm leave
  • On manager (removes the whole swarm):
  docker swarm leave --force

🎯 Conclusion

You just created a 3-node Docker Swarm cluster like a boss! This setup is perfect for learning how real-world deployments and scaling work β€” and it’s just the beginning.

Now that you have your cluster:

  • Try scaling services up/down.
  • Deploy your own apps.
  • Learn about Swarm secrets, configs, and rolling updates.

Let Docker do the heavy lifting β€” your apps deserve a swarm! 🐝


This content originally appeared on DEV Community and was authored by SOVANNARO