Add Nodes In Docker Swarm

Previously we had seen that to join a node to the cluster we need a command with the token provided by the master node. Suppose we lose that token and we want to add a new node into the cluster.

Adding a new worker node

To add a worker node to the cluster, we will use the below command on the master node -

$ docker swarm join-token worker

output:

root@master:~# docker swarm join-token worker
To add a worker to this swarm, run the following command:
    docker swarm join --token SWMTKN-1-5mjantlahzsaeij4l7n8716gs4ce03rk261aogw9hgn1tnlip1-2rrk2p8shojy755bgxzjz1e6t 192.168.0.123:2377
root@master:~#

To join the worker to the cluster, run the command that we get from the output.

Adding a new master node

To add a master node to the cluster, we will use the below command on the master node -

$ docker swarm join-token manager

output:

root@master:~# docker swarm join-token manager
To add a manager to this swarm, run the following command:
    docker swarm join --token SWMTKN-1-5mjantlahzsaeij4l7n8716gs4ce03rk261aogw9hgn1tnlip1-b6g7e5myjll06k4dxiod1el9e 192.168.0.123:2377
root@master:~#

Run the above command on any node to add it as a master in the cluster.