Cannot kill container: foo: Container foo is not running

Perhaps kill is incorrect terminology, or I'm at least using it incorrectly.

How do I destroy docker containers? Put them in the trash. Delete. Remove. Erase.

docker container kill $(docker ps -a -q | awk '{print $1}')

doesn't quite work:

Error response from daemon: Cannot kill container: 06e44d24ba8d: Container 06e44d24ba8d3df83e10a1829f04755cb9053faa68ab3dabccd10c3ee1c80322 is not running
Error response from daemon: Cannot kill container: 22539a069e3b: Container 22539a069e3b8bbbd27b062603a7667857ac1a5e64242004fe7b72411a9cdbca is not running
Error response from daemon: Cannot kill container: 1f7cf43ab398: Container 1f7cf43ab398e6e18416f69fc947b49d9792b1932a4b157f0514f9f6638ca185 is not running
Error response from daemon: Cannot kill container: 7fc8c24ccabe: Container 7fc8c24ccabef04215df9ba7b8c171df6b963942e6e90c92a462cc0ab9d5dcb0 is not running

See also:

1 Answer

docker kill will not destroy containers, it will just kill (stop) the running containers. But docker ps -a will show also the non-running containers, so you get an error for all these non-running containers.

Leave out the -a to kill only all running containers:

docker kill $(docker ps -q)

Use docker stop instead of docker kill if you want the processes to first try to terminate themselves (SIGTERM) instead of killing directly (SIGKILL).

Or use docker rm to remove (destroy) containers:

docker rm --force $(docker ps -a -q)

--force or -f is needed to also rm running containers.

Note:
this will remove all containers.

Use docker container prune to remove all stopped containers.


Please read the docs or run docker help to get more information about all the commands.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like