How to Stop All Docker Containers?

To stop all running Docker containers, you can simply use the following command:

docker stop $(docker container ls -q)

This command does the following:

  • docker container ls -q returns the list of ids of all running containers;
  • docker stop attempts to trigger a graceful termination of the containers (by sending the SIGTERM signal to the main process inside the container).

You can also use docker ps -q instead of docker container ls -q. However, the latter is the newer syntax and is more readable than the former.

You can also choose to immediately stop/kill all running containers by using the docker kill command instead of docker stop. Please note though that there are some subtle differences between the two commands.

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.