top of page

How to join a worker node to a Docker Swarm

To join a worker node to a Docker Swarm, you need to use the docker swarm join command on the worker node. Here are the general steps:


1. Retrieve Swarm Join Token from Manager Node:

On the manager node, you can generate a join token. Run the following command:

[root@siddhesh ~]# docker swarm join-token worker
To add a worker to this swarm, run the following command:

    docker swarm join \
    --token SWMTKN-1-1d2mlbpf9g9e5s7gt5vxqtlmmjxhu5eevmfpyjqf8kwpaxzypo-7voy6a3d6x4vvd6676pt0q745 \
    192.168.1.2:2377

[root@siddhesh ~]#

Where,

docker swarm join: This is the base command for a worker node to join a Docker Swarm.

--token SWMTKN-1-1d2mlbpf9g9e5s7gt5vxqtlmmjxhu5eevmfpyjqf8kwpaxzypo-7voy6a3d6x4vvd6676pt0q745: This is the token that authenticates the worker node to join the Swarm. Tokens are time-limited and have specific privileges (in this case, for joining as a worker).

192.168.1.2:2377: This is the address of the manager node and the port (2377) on which the Swarm is listening.


2. Execute Join Command on Worker Node: Log in to the worker node and run the docker swarm join command with the token you obtained in the previous step.

[root@worker ~]#     docker swarm join --token SWMTKN-1-1d2mlbpf9g9e5s7gt5vxqtlmmjxhu5eevmfpyjqf8kwpaxzypo-7voy6a3d6x4vvd6676pt0q745 172.32.1.115:2377
This node joined a swarm as a worker.
[root@worker ~]#

3. Verify Join Status: On the manager node, you can verify that the worker node has joined the swarm by running:

[root@siddhesh ~]# docker node ls
ID                           HOSTNAME               STATUS  AVAILABILITY  MANAGER STATUS
ieh09e2qqupx90mhmr1k08hm3 *  siddhesh               Ready   Active        Leader
xjrwvile6z8jmj762e2svidas    worker.builddevops.com  Ready   Active
[root@siddhesh ~]#

The newly joined worker node should appear in the list.


4. Scale up Nginx Service:

Let's add one more task to the existing node of nginx.

[root@siddhesh ~]# docker service scale nginx-service=4
nginx-service scaled to 4
[root@siddhesh ~]#

5. Check the status of Running Tasks:

[root@siddhesh ~]# docker node ls
ID                           HOSTNAME               STATUS  AVAILABILITY  MANAGER STATUS
ieh09e2qqupx90mhmr1k08hm3 *  siddhesh               Ready   Active        Leader
xjrwvile6z8jmj762e2svidas    slave.builddevops.com  Ready   Active
[root@siddhesh ~]# docker node ps ieh09e2qqupx90mhmr1k08hm3
ID            NAME             IMAGE         NODE      DESIRED STATE  CURRENT STATE           ERROR  PORTS
h9hv3gspqazd  nginx-service.1  nginx:latest  siddhesh  Running        Running 20 minutes ago
u957m6ksigqw  nginx-service.2  nginx:latest  siddhesh  Running        Running 20 minutes ago
ya7at6vbakak  nginx-service.3  nginx:latest  siddhesh  Running        Running 20 minutes ago
[root@siddhesh ~]# docker node ps xjrwvile6z8jmj762e2svidas
ID            NAME             IMAGE         NODE                   DESIRED STATE  CURRENT STATE          ERROR  PORTS
2at4wpz4noig  nginx-service.4  nginx:latest  slave.builddevops.com  Running        Running 5 minutes ago
[root@siddhesh ~]#

As you can see in the output above, the nginx-service.4 task is now running on the newly added node, i.e., xjrwvile6z8jmj762e2svidas, which is from a remote server.

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page