How to Setup and Configure Docker Swarm Cluster

In this tutorial, you will learn how to set up a four node docker swarm cluster.

Prerequisites

  • Minimum two nodes with Docker installed ( swarm manager and cluster nodes)
  • All the nodes should be able to talk to each other using public or private IP addresses.

In this setup, I have total 4 nodes. 1 Swarm manager node and three other nodes to join the cluster with the following private IP addresses

Follow the steps given below for a multi node swarm cluster.

On Manager Node

1. Execute the following command with the manager nodes IP for initializing the swarm cluster.

For example,

You will get the following output once swarm is initialized.

As you can see, the output has the steps to join other nodes to this swarm manager node.

READ  Jenkins Tutorial For Beginners - Getting Started Guide

2. To know the swarm cluster info, execute the following command.

In the output, you will see the following.

3. To know the information about all the nodes in the cluster, you can run the following command.

On Node 1, 2 and 3

Now that we have the swarm manager ready, we can add our other nodes to the manager to form a multi node cluster.

1. Execute the swarm join command from the manager output on all the extra nodes as shown below. The swarm token and IP will change based on your environment.

Note: You can get the swarm token with the command by executing docker swarm join-token worker on the manager node.

Swarm Configuration and Testing

1. Once you joined all the extra nodes, you can list the swarm node information by executing the following command on the manager node.

You will get the output will the swarm cluster info as shown below.

Now our cluster is ready. You can start deploying applications to your swarm cluster.


ONLINE COURSE:  Docker Mastery: The Complete Toolset From a Docker Captain

Check out the docker course which thousands of students have already enrolled.

  • Learn Docker and Compose
  • Best practices for making Dockerfiles
  • Learn to build multi node swarm cluster
  • Rolling application deployments without downtime

 

Free DevOps Resources

Get DevOps news, tutorials and resources in your inbox. A perfect way If you want to get started with devops. Like you, we dont like spam.

5 comments

  1. Pingback: Docker Tutorial : Getting Started With Docker Swarm

  2. Nguyễn Văn Tân Reply

    #sudo docker -H tcp://10.0.1.61:5001 info

    –> Please tell me how can we use port 5001, instead should we use 2375?
    Because I didn’t see port 5001 opened.
    Thanks

    • CoolDarthVader Reply

      It was opened when you ran …
      sudo docker -H tcp://10.0.1.61:2375 run -d -p 5001:2375 swarm manage token…

      Took me a while to figure out that by doing:
      docker -H tcp://10.0.1.61:2375 ps -a ==> you see containers spawned only on swarm master.

      but by doing:
      docker -H tcp://10.0.1.61:5001 ps -a ==> you see containers spawned on the swarm nodes (not master).
      .

Leave a Reply

Your email address will not be published. Required fields are marked *