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 -qreturns the list of ids of all running containers;
docker stopattempts to trigger a graceful termination of the containers (by sending the
SIGTERMsignal 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.