Removing a node from a swarm :
- List the nodes in the swarm by running the following command on the Manager Node.
docker node ls
- Log on to the desired node and run the following command to remove the node forcefully from the swarm.
docker swarm leave -f
The node will still appear in the node list on the Manager Node, but it will be marked as down. It no longer affects swarm operation.
- To remove the node from the Managers list ( -f = forcefully)
docker node rm <Node ID> -f
The Node ID is seen in the output of the command in the first step.
Adding a node to a swarm :
- The following command on the Manager Node displays the token for particular swarm. There are two; one for adding a Manager and one for a Worker.
docker swarm join-token manager
docker swarm join-token worker
Tip - When adding a Core Node to a swarm use the worker form of the command.
- The output of the above command tells you the next command which to be run on the node to be added to the swarm.
See the example below