Safely Remove a Docker Swarm Node with docker node rm
You will remove a Docker Swarm node from the cluster's node list, verify the result, and choose the right path for a stopped, active, unreachable or compromised node. Allow about ten minutes for a stopped worker, longer if you need to inspect services or protect manager quorum. The examples use Docker CE CLI 29.8.1, installed here as package version 5:29.8.1-1~ubuntu.24.04~noble.
The route
Jump straight to the step you need, or tick off Done means at the end.
This is a cluster-management operation. Run it from a reachable Swarm manager, with credentials that can administer that manager. It changes Swarm state, but it does not uninstall Docker from the removed machine and it does not remove the machine's local files. If you only want a node to stop receiving service tasks temporarily, drain it instead of removing it.
1. Check the command and your context
The installed command accepts one or more node names or IDs. It has one option, --force (also -f):
$ docker node rm --help
Usage: docker node rm [OPTIONS] NODE [NODE...]
Remove one or more nodes from the swarm
Options:
-f, --force Force remove a node from the swarm
Confirm the client version and list the nodes before changing anything. These checks are ordinary commands, but docker node ls must be run against a manager:
$ docker version --format '{{.Client.Version}}'
29.8.1
$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
abc123... * manager-1 Ready Active Leader
def456... worker-1 Down Active
Record the exact ID or hostname of the target. Names are easier to read; IDs are safer when names are similar. Do not infer the target from a remembered machine name.
2. Check role, tasks and manager quorum
Inspect the target before removing it:
$ docker node inspect NODE_NAME --pretty
ID: def456...
Hostname: worker-1
Status:
State: Down
Availability: Active
Manager Status:
...
Use the real node name or ID in place of NODE_NAME. The output is host-specific. Pay attention to Status.State, Availability and whether Manager Status is present. A manager participates in the Raft quorum; removing one can make the whole Swarm unable to accept management operations.
Before touching a manager, count the remaining reachable managers in docker node ls. Keep a majority available, and prefer an odd number of managers. Docker's documented examples give the practical boundary: a three-manager Swarm can lose one manager and retain quorum; a five-manager Swarm can lose two. Never remove the last manager as a routine cleanup step.
Checkpoint: if the target is a manager, stop here unless you have a specific maintenance or recovery plan. Demote it first, then re-check that the remaining managers still have quorum:
$ docker node demote MANAGER_NAME
Manager MANAGER_NAME demoted in the swarm.
$ docker node ls
Demotion is a separate state change and may affect scheduling. If it would leave too few managers, add or promote a replacement before proceeding.
3. Remove a node that has already stopped
For a worker whose Engine is stopped or otherwise reports Down, use the normal form. This is the preferred removal because it does not bypass the node-state check:
$ docker node rm worker-1
worker-1
The official documentation shows a success line in the form Node worker-1 removed from swarm; the exact CLI output can vary by Docker release. Verify that the node no longer appears:
$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
abc123... * manager-1 Ready Active Leader
Removal from this list is not a remote uninstall. If the old host comes back, its local Docker Engine still has its own state. Rejoin it only with a fresh, current join command issued by a manager, and inspect the result before deploying work there.
4. Handle an active node without forcing it
If the node is still running, the normal command refuses to remove it:
$ docker node rm worker-1
Error response from daemon: rpc error: code = 9 desc = node worker-1 is not down and can't be removed
That refusal protects running Swarm tasks. For planned maintenance, first prevent new placement and let services move away:
$ docker node update --availability drain worker-1
worker-1
$ docker node inspect worker-1 --format '{{.Spec.Availability}}'
drain
$ docker node ps worker-1
Draining affects Swarm service tasks. It does not remove standalone containers created with docker run, Compose or the Engine API. Check service health and task placement separately. When the host is safely stopped and the node reports Down, run the normal docker node rm worker-1 command.
5. Force removal only for an inaccessible or compromised node
Use --force when the node cannot be shut down cleanly, is unreachable, unresponsive or compromised. This is destructive to the Swarm membership record and can interrupt tasks, so confirm the target twice before pressing Enter:
$ docker node ls
$ docker node inspect worker-1 --pretty
$ docker node rm --force worker-1
Node worker-1 removed from swarm
Do not use force merely to silence the active-node error during routine maintenance. A forced removal does not guarantee graceful task shutdown, data flushes or application-level recovery. If the node held stateful workloads, follow the workload's backup and failover procedure first.
There is no undo flag for docker node rm. Recovery means restoring the host or service from your own backup, then joining the machine to the Swarm again as a new node. A removed manager must be rejoined with a fresh manager join procedure after the cluster has been stabilised; do not copy another manager's Swarm data directory.
6. Diagnose the common failures
An error saying the command must run on a manager means the Docker endpoint you are using is not a manager. Switch to a reachable manager context and repeat the read-only docker node ls check. A missing or ambiguous target usually means you supplied the wrong name or ID; list nodes again rather than guessing.
A timeout or context deadline exceeded during removal can indicate that the managers have lost quorum. Do not repeatedly retry a destructive command. Restore communication with enough managers first, then inspect the membership. Existing tasks can continue running while management operations are unavailable, but node removal will not succeed without a functioning manager quorum.
Checkpoint: after every successful removal, run docker node ls, confirm the expected manager count, and check affected services with docker service ls and docker service ps SERVICE_NAME. These commands do not alter state.
Done means
- The command was run from a reachable Swarm manager.
- The target's role and state were checked before removal.
- A planned removal used drain, shutdown and normal
docker node rm; force was reserved for an inaccessible or compromised node. - Manager quorum remains healthy and the removed node is absent from
docker node ls. - Services and any stateful workload have been checked after the membership change.