๐Ÿณ Creating a 3-Node Docker Swarm Cluster: A Simple & Fun Guide

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! ๐Ÿ

Similar Posts