To stop all Docker containers simply run the following command in your terminal:
docker kill $(docker ps -q)
How It Works #
- The docker ps command will list all running containers.
- The -q flag will only list the IDs for those containers.
- Once we have the list of all container IDs, we can simply run the docker kill command, passing all those IDs, and they’ll all be stopped!
docker kill sends SIGKILL, so the containers have no time to shut down cleanly. For a graceful shutdown use docker stop $(docker ps -q).