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.

[email protected] ~ % docker container stop $(docker ps -a -q)

8389aff2f804
64718fec99f4
b8d66e2701e2
4bd42b951052
b5e1edc7ef1f

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.

Enjoy!!!

Please follow and like:

Leave a Reply

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

Enquire now

Give us a call or fill in the form below and we will contact you. We endeavor to answer all inquiries within 24 hours on business days.