Skip links

A simple way to stop all Docker containers

This is just a quick reminder post to illustrate how to stop all docker containers that are running within a given environment.

As many may already know, you can use the standard Docker stop command to stop a given container.  What if you want to stop all containers within your development environment?  The simple way is to combine Docker commands.

The first command that is useful is to find out what is running.  In this case, the command is:

docker pa -a

This command will return a list of all the containers that are present  on the system – running or exited.  What you want to get at this point is the “CONTAINER ID”.  If you add in the -q option, the resulting return set will only display the “CONTAINER ID” that are needed.

bocurtis@MacBook-Pro ~ % docker container stop $(docker ps -a -q)






The next command that is needed is the stop command.  This command is the command that will actually stop all the containers that is it passed.  Typically this would be one-by-one, but you are trying to stop all of them at one time.  To do this, you simply pass the docker ps command to the  container stop command like so:

docker container stop $(docker ps -a -q)

At this point, you can perform a process (ps -a) command and see that everything has been stopped.

Hope the helps and is a quick reference to stopping more than one container.


Leave a comment