Create, add node to the swarm cluster of Docker engine
Create a Swarm:
sunny@Oracle1:~/Desktop$ docker swarm init
Swarm initialized: current node (qz7ctlqi486ogcmfchj8gphsb) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-342v4g5c4mk1pl0nf40d3vd75ni67fzt1m0s413hq583wwripm-07xhp3rarcbq78rxl29nfsbt7 10.0.2.15:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
Note: token is needed to join the another node on swarm cluster
Check the information of nodes as leader:
sunny@Oracle1:~/Desktop$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
qz7ctlqi486ogcmfchj8gphsb * Oracle1 Ready Active Leader 20.10.22
Join another node as worker:
join node2 as worker, so run and get the key and command on node1:
#docker swarm join-token worker
sunny@Oracle1:~/Desktop$ docker swarm join-token worker
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-342v4g5c4mk1pl0nf40d3vd75ni67fzt1m0s413hq583wwripm-07xhp3rarcbq78rxl29nfsbt7 10.0.2.15:2377
You go to second node and run this command to add this node as worker:
Go to the second node and run the upper command to directly add the node in cluster:
node2# docker swarm join --token SWMTKN-1-342v4g5c4mk1pl0nf40d3vd75ni67fzt1m0s413hq583wwripm-07xhp3rarcbq78rxl29nfsbt7 10.0.2.15:2377
Check the node added in swarn cluster:
docker node ls