Forcibly remove an inaccessible node from the swarm
In this step, you will learn how to forcibly remove a node from the swarm that is inaccessible or unresponsive. This is necessary when a node has failed and cannot be gracefully removed.
First, let's list the nodes in the swarm again to get the node ID.
docker node ls
Identify the ID
of the node you want to forcibly remove. In our current setup, this is the only node, which is the manager.
To forcibly remove a node, you use the docker node rm
command with the --force
flag, followed by the node ID. Replace <node_id>
with the actual ID.
docker node rm --force <node_id>
You should see output indicating that the node has been removed.
Node <node_id> removed from swarm
Now, list the nodes in the swarm again to confirm that the node has been removed.
docker node ls
You will see an error message because you have removed the only node (the manager) from the swarm, and the current Docker daemon is no longer part of a swarm.
Error: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to a swarm.
This confirms that the node was successfully removed from the swarm, even though it was the manager node. Forcibly removing a manager node should be done with caution as it can impact the availability of your swarm if there are no other managers.