How to Kill All Docker Containers?

You can immediately stop/kill all running Docker containers by using the following command:

docker kill $(docker container ls -q)

This command does the following:

  • docker container ls -q returns the list of ids of all running containers;
  • docker kill immediately stops/kills the containers (by sending the SIGKILL 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 gracefully stop all running containers by using the docker stop command instead of docker kill. 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.