Adding Nodes to a Docker Swarm Cluster
Joining Worker Nodes to the Swarm
To add worker nodes to your Docker Swarm cluster, you can use the docker swarm join
command. This command requires the join token, which can be obtained from the manager node.
On the manager node, run the following command to get the join token:
docker swarm join-token worker
This will output a command that you can use to join a worker node to the swarm, for example:
docker swarm join --token SWMTKN-1-49nj1cmql0jkz5s7riia...
Now, on the worker node, run the command provided by the manager node to join the swarm.
Joining Manager Nodes to the Swarm
You can also add manager nodes to your Docker Swarm cluster. This is useful for increasing the fault tolerance and high availability of your swarm.
To add a new manager node, run the following command on the new node:
docker swarm join --token SWMTKN-1-61ztec9roubhglb7xbc...
The token used to join the manager node can be obtained from an existing manager node using the following command:
docker swarm join-token manager
Verifying Node Status
After adding nodes to the swarm, you can use the docker node ls
command to view the status of all the nodes in the cluster. This will show you the role of each node (manager or worker) and their current status.
docker node ls
This will output a table with information about each node in the swarm.
Removing Nodes from the Swarm
If you need to remove a node from the swarm, you can use the docker node rm
command. For example, to remove a worker node:
docker node rm worker-node
To remove a manager node, you'll need to first demote it to a worker node, and then remove it:
docker node demote manager-node
docker node rm manager-node
Remember to plan for node removal carefully, as it may impact the availability and resilience of your swarm.