Leaving a Swarm

A worker leaves with docker swarm leave, run on itself; managers reschedule its tasks and list it as Down until docker node rm. A manager must be demoted or forced out with --force, which on the last manager destroys the swarm's Raft state, secrets included:

Removing the stack, then the nodes, then the labShell
m1 stack rm booknest >/dev/null; sleep 5
docker exec l3-swarm-3 docker swarm leave
until [ "$(m1 node ls -f name=swarm-3 --format '{{.Status}}')" = Down ]; do sleep 1; done
m1 node ls --format '{{.Hostname}} {{.Status}}'
m1 node rm swarm-3
docker exec l3-swarm-2 docker swarm leave >/dev/null
m1 swarm leave 2>&1 | cut -c 1-90; m1 swarm leave --force
docker rm -f -v l3-swarm-1 l3-swarm-2 l3-swarm-3 >/dev/null
docker network disconnect l3-swarm-net l3-registry && docker network rm l3-swarm-net
Output
Node left the swarm.
swarm-1 Ready
swarm-2 Ready
swarm-3 Down
swarm-3
Error response from daemon: You are attempting to leave the swarm on a node that is partic
Node left the swarm.
l3-swarm-net

stack rm removed the services and the overlay network, but not the external db_password secret or the pgdata volume, which stays on the node that created it. The last manager refused to leave until forced. The -v on docker rm deletes each node's anonymous /var/lib/docker volume, which held its images and containers.