How to Stop All Docker Containers?

Quick tip to gracefully terminate all running 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.


Hope you found this post useful. It was published . Please show your love and support by sharing this post.