Waar IT online marketing kruist!

Bulk Stopping/Starting/Removing docker containers

Docker whale logo

Maintaining all docker containers in bulk is something that can easily be achieved with the following bash/terminal commands.

The commands

Stopping all docker containers

Removing all docker containers

Starting all docker containers

How it works

The command docker ps -a -q will generate a list of all initialized docker containers. This list will only contain the ID’s of those containers.

By using $(command) you create a variable containing all the results of the command.
By adding this right after the docker start/rm/stop command will be executed with each result of the variable as parameter.

Docker: Docker application
ps: Tell docker to show you the Process Status
-a: Tell docker to generate a list of all the containers independent of their state.
-q: Tell docker to only output the ID numbers of the containers.


The only disadvantage is that these commands will cycle over all the containers loaded into docker at that specific time. This means that it’ll try to stop already stopped containers, run already running containers or try to remove still running containers.

Even though it’s not critical the latter might be annoying if you assume that everything is properly removed.
It also might take a while if you have a lot of containers.

I am running Docker on a Debian machine, if these commands don’t work try replacing
with docker.io .