In this tutorial, you’ll learn how to set up a 3-node warm cluster using Docker Swarm, a native clustering tool for Docker that turns a group of Docker engines into a single virtual Docker engine. This hands-on guide will take you through the process of initiating a swarm, joining nodes to it, and deploying services across the nodes. This setup is ideal for testing scalability and high availability without setting up complex infrastructure.

Hands-On Guide: Creating a 3-Node Warm Cluster

Step 1: Prepare Your Environment

Start by visiting Play with Docker. Create 3 instances, which will serve as your nodes within the Docker Swarm.

Step 2: Ensure Node Communication

From each node, use the ping command to confirm network connectivity to the other nodes. Ensure you can ping each node from the others three times to confirm proper network setup.

ping -c 3 <node_ip_address>

Step 3: Initialize the Docker Swarm

On node1, initialize a new Docker Swarm. This command sets up node1 as the manager node, making it responsible for managing swarm state and scheduling services:

docker swarm init --advertise-addr <node1_ip_address>

Step 4: Join the Swarm as a Worker

On node2, join the swarm as a worker using the token provided by node1. Workers are responsible for running swarm services but do not manage swarm infrastructure:

docker swarm join --token <your_token> <node1_ip_address>:2377

Step 5: Promote Node2 to Manager

On node1, promote node2 to a manager to allow it to help manage the swarm and maintain high availability:

docker node update --role manager node2

Step 6: Prepare Node3 to Join as Manager

From node2, generate a command to allow node3 to join the swarm as a manager. This step ensures node3 can also manage the swarm and participate in scheduling decisions:

docker swarm join-token manager

Step 7: Join Node3 to the Swarm

Execute the join command on node3, obtained from node2, to add it as another manager:

docker swarm join --token <your_token> <node1_ip_address>:2377

Step 8: Deploy a Service Across the Swarm

Create a new service with three replicas of an Alpine container that pings an external IP address. This command sets up a distributed service that runs across all swarm nodes:

docker service create --replicas 3 alpine ping

Step 9: Monitor Service Deployment

Inspect running tasks across the swarm to confirm the service deployment:

docker service ps <service_name>

Check containers running on the current node to see details about the tasks executed there:

docker container ls

View tasks running on a specific node, verifying that tasks are distributed across the swarm:

docker node ps <node_name>


Congratulations! You have successfully set up a 3-node warm cluster using Docker Swarm. This configuration allows you to explore Docker’s capabilities in managing and orchestrating distributed applications across multiple nodes. Now, you’re equipped to scale services dynamically and manage multi-container applications across a cluster of servers.

Next Steps: Experiment with different Docker Swarm features and configurations to enhance your understanding of container orchestration in larger production environments. This foundational knowledge paves the way for more advanced deployments and management strategies using Docker.