Containers

Docker Stop All Containers in 3 Ways

Learn three ways in docker to stop all containers on a host. We look at the docker command line, Portainer, and another tool called Komodo

If you are working with Docker for the first time or starting to run multiple docker containers on a single host or across multiple hosts, you are probably starting to manage the hosts and running into just day-to-day housekeeping items you want to accomplish, like stopping containers, rebooting hosts, etc. One of the basic tasks you may want to know how to do is stopping all containers on a host. Let’s look at the topic of docker stop all containers and we will see three ways to do this.

1. Using the command line

This is the first way that you can use to stop all containers. Using the command line is simple, its efficient, and it is effective to perform the task of stopping all containers. What is the command?

docker stop $(docker ps -a -q)

In the above command the docker stop portion is the command to stop containers. However, we are passing in the value of a command $(docker ps -a -q). This is what that portion does:

  • docker ps -a -q: Lists all containers (-a for all, -q for only the container IDs).
  • docker stop: Stops the containers of the IDs that are captured as arguments.
  • $(): This captures the output of docker ps -a -q and passes it as an argument to docker stop.
Stopping all docker containers using the docker command line
Stopping all docker containers using the docker command line

In the command output above, you will see the container IDs enumerated that were stopped and then the command will return to your bash prompt.

2. Using Portainer

After the command line, if you are a more “point-and-click” type person who likes doing things from a GUI, Portainer offers a great solution to manage docker in general and it allows you to stop all containers at the same time as well.

Once you onboard your docker container host into Portainer by installing the portainer agent, you can browse to containers in the left-hand navigation menu. Then select all containers with the tick box above the list of containers. Place a check there, and then click the stop button.

Stopping all containers using portainer
Stopping all containers using portainer

Portainer is a free tool using the community edition that you can run with most features and functionality. You can also get a free 3-node business edition license that allows you to have even more features. You can check out that offer here: Take 3.

Of course there are many other advantages to using something like Portainer for stopping your containers as it is a solution that is complete when it comes to fully managing the environment, including lifecycle management, etc.

3. Komodo

There is another free tool that provides a really great GUI to manage your docker containers as well, called Komodo. I recently posted a detailed post covering many of the features of Komodo. You can read that here: Portainer Alternative Komodo for Docker Stack Management and Deployment.

In brief, Komodo is a free and open source solution that you can download without limitations and start adding your docker container hosts. It has really nice features for a free tool and is on par with Portainer for most features of docker management. Let’s look at how to bulk stop containers with it.

In Komodo, you navigate to your docker container host “server” as they are called in Komodo. Then you will see under the Execute section of the dashboard, you have the option to Stop Containers.

Docker stop all containers with komodo
Docker stop all containers with komodo

If you click the button to stop containers, Komodo actually prompts you to confirm that you want to stop all containers. You have to type in the name of the docker container host and then click Stop Containers and then Confirm.

Docker stop all containers with komodo confirmation
Docker stop all containers with komodo confirmation

Komodo will bulk stop all the docker containers running on your host. One of the notes to make about Komodo. In my testing, it won’t stop the “periphery” agent that is its equivalent to the portainer agent. I am guessing this function has been coded this way so that you don’t stop the agent where komodo can’t connect to the docker host. Keep this in mind though if you literally want to stop all containers.

Wrapping up

If you need to stop all docker containers running on a host, using the three methods shown in the blog will help you to have a variety of ways to do this. Keep in mind that the command line solution is native to docker. So, you won’t have to install any other tools or utilities. However, Portainer and Komodo are two very good tools to have GUI management for your docker container hosts. Each of these tools allow you to stop all the running docker containers on your container hosts.

Subscribe to VirtualizationHowto via Email ๐Ÿ””

Enter your email address to subscribe to this blog and receive notifications of new posts by email.



Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com, and a 7-time VMware vExpert, with over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, He has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family. Also, he goes through the effort of testing and troubleshooting issues, so you don't have to.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.