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)
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.
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”.