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)
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!!!
Current Oracle Certs
Bobby Curtis
I’m Bobby Curtis and I’m just your normal average guy who has been working in the technology field for awhile (started when I was 18 with the US Army). The goal of this blog has changed a bit over the years. Initially, it was a general blog where I wrote thoughts down. Then it changed to focus on the Oracle Database, Oracle Enterprise Manager, and eventually Oracle GoldenGate.
If you want to follow me on a more timely manner, I can be followed on twitter at @dbasolved or on LinkedIn under “Bobby Curtis MBA”.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.