Home  Tech   How to exit ...

How to exit Docker Swarm mode

Exiting Swarm mode involves removing the current node from the Swarm cluster. If the node is a manager node, you need to first demote it before leaving the Swarm. Here's how to do it:

If the Node is the Only Manager

If the node you are trying to remove is the only manager node in the Swarm, you can directly leave the Swarm. This will effectively disband the Swarm cluster.

  1. Leave Swarm Mode
    docker swarm leave --force
    

If the Node is a Manager and There are Other Managers

If the node is a manager and there are other manager nodes in the Swarm, you need to demote it first and then leave the Swarm.

  1. Demote the Manager Node

    docker node demote <node-name>
    
  2. Leave Swarm Mode

    docker swarm leave
    

Replace <node-name> with the actual name of the node you want to demote.

If the Node is a Worker

If the node is a worker node, you can directly leave the Swarm.

  1. Leave Swarm Mode
    docker swarm leave
    

Step-by-Step Example

Step 1: Check Node Status

First, check the status of the nodes in your Swarm to understand their roles.

docker node ls

Example output:

ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS
tqr3f58p3j3n5f4e2lyz9f8dm *   manager-node        Ready               Active              Leader
d3n5f4e2lyz9f8dm                worker-node-1        Ready               Active              
q8g4e2lyz9f8dm                 worker-node-2        Ready               Active              

Step 2: Demote the Manager (if applicable)

If the node you want to remove is a manager (and not the only manager), demote it first.

docker node demote manager-node

Step 3: Leave Swarm Mode

Leave the Swarm from the node you want to remove.

docker swarm leave

If this node is the only manager, use --force to disband the Swarm:

docker swarm leave --force

After running these commands, the node will leave the Swarm mode, and if it was the only manager node, the Swarm cluster will be disbanded. If there are other nodes in the Swarm, they will continue to operate as part of the Swarm.

Published on: Jun 16, 2024, 09:46 PM  
 

Comments

Add your comment