In this tutorial, you will learn how to set up a four node docker swarm cluster.
- 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
Manager - 10.140.0.2 Node1 - 10.140.0.6 Node2 - 10.140.0.4 Mode3 - 10.140.0.5
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.
docker swarm init --advertise-addr <MANAGER-IP>
docker swarm init --advertise-addr 10.140.0.2
You will get the following output once swarm is initialized.
[[email protected] ~]$ docker swarm init --advertise-addr 10.140.0.2 Swarm initialized: current node (0qjtv7kblhbrbub4yyk1tq1e7) is now a manager. To add a worker to this swarm, run the following command: docker swarm join \ --token SWMTKN-1-3l50pb6ko5ci23134wzt17gqkb4nsbv4e52ciwdwq80hmmx1si-d3kv6s6qtgf0crqmz9dxix2oc \ 10.140.0.2:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions. [[email protected] ~]$
As you can see, the output has the steps to join other nodes to this swarm manager node.
[irp posts=”647″ name=”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.
Swarm: active NodeID: 0qjtv7kblhbrbub4yyk1tq1e7 Is Manager: true ClusterID: zj0ioxrvl0tsyxasbhwyu947l Managers: 1 Nodes: 1
3. To know the information about all the nodes in the cluster, you can run the following command.
docker node ls
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.
sudo docker swarm join \ --token SWMTKN-1-3l50pb6ko5ci23134wzt17gqkb4nsbv4e52ciwdwq80hmmx1si-d3kv6s6qtgf0crqmz9dxix2oc \ 10.140.0.2:2377
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.
sudo docker node ls
You will get the output will the swarm cluster info as shown below.
[[email protected] ~]$ sudo docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS 0qjtv7kblhbrbub4yyk1tq1e7 * manager Ready Active Leader adig05zbyuxt4x0oltrbrc523 node2 Ready Active bzupprwwasy6vvwh4hn0s4txz node1 Ready Active ug20slq1qyk6uzwgfv3a5zd86 node3 Ready Active
Now our cluster is ready. You can start deploying applications to your swarm cluster.
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