Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: February 10, 2025
Docker Swarm is a built-in clustering and orchestration mechanism for Docker containers. It offers capabilities for deploying and maintaining services in a distributed environment and permits the administration of a cluster. Sometimes, though, we might want to turn off Docker Swarm mode, either to switch to another orchestration tool or just because we no longer need the clustering feature.
In this tutorial, we’ll walk through the step-by-step process of turning off the Docker Swarm mode.
Before disabling Swarm mode, it’s important to understand the implications:
In order to disable the Docker Swarm Mode, we’ll first start by checking the current status using the docker info command. By doing so, the node’s involvement in a swarm will be verified. Next, we’ll exit the node from the cluster. Finally, we’ll verify the mode again to ensure the node is independent.
Let’s first identify if the current node is a part of the Swarm cluster. We can accomplish this by executing the below command:
$ docker info | grep Swarm
Swarm: active
The output mentions that the node is part of the Swarm cluster.
We need to remove the Docker instance from the Swarm to disable the Swarm mode. To do this, we can use the command below:
$ docker swarm leave
Node left the default swarm.
This will remove the worker node from the swarm cluster. The node will remain tagged as down and visible in the node list. Use the node rm command to eliminate an inactive node from the list.
Note that the above command will be for worker nodes only. We can use the –flag to remove a manager node from the swarm:
$ docker swarm leave --force
We should use the –force flag only in single-node swarms or when the swarm will be decommissioned after the manager departs. The safe way to remove a manager from a swarm is to first demote it to a worker. Once demoted, simply instruct the node to leave the Swarm without using the –force flag.
By following these steps, we maintain the health and stability of the Docker Swarm cluster. This ensures that critical cluster state information is not inadvertently lost or corrupted.
Once all the nodes left the Swarm, confirm that Docker Swarm mode is disabled by running the docker info command again:
$ docker info | grep Swarm
Swarm: inactive
The output indicates that the Swarm mode is no longer active.
After disabling the Swarm mode, let’s make sure to clear out any remaining states or configurations that might not be in use anymore. We should use the following commands to list and remove Docker networks:
$ docker network ls --filter driver=overlay
$ docker network rm <network_name>
The above command will list all the overlay Docker networks, and we can remove the desired network using the docker network rm command. Let’s also remove the volumes created by Swarm using the below command:
$ docker volume ls --filter label=com.docker.swarm
$ docker volume rm <volume_name>
Here, we first filter all the Docker volumes using the label com.docker.swarm. Further, we can delete those volumes using the docker volume rm command.
In this article, we learned the steps to disable the Docker Swarm mode. Disabling Docker Swarm mode is straightforward, but it’s important to understand the implications and take necessary precautions.
First, we identified the current state of the Swarm using the docker info command. Next, we disabled the Swarm by removing nodes one by one. Finally, we verified the state again to ensure the Swarm mode was disabled. This makes the transition to a simpler Docker setup or another orchestration tool.