Last Updated: September 24, 2023
·
1.943M
· fgrehm

Stop / remove all Docker containers

One liner to stop / remove all of Docker containers:

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

32 Responses
Add your response

My hard drive was full, total lockup, this was a saviour for me! thanks =D

over 1 year ago ·

that's great. I needed to stop and rm all containers before removing an docker image.

over 1 year ago ·

great command!

over 1 year ago ·

Having bookmarked this immensely useful tip a while ago, the two-liner above :) can be now done in one line:
docker rm -f $(docker ps -a -q)

And similar for all images:
docker rmi $(docker images -q)

over 1 year ago ·

docker rm $(docker images -q) or docker rmi $(docker images -q)

works just fine, after you stopped them

over 1 year ago ·

docker rm $(docker images -q) or docker rmi $(docker images -q)

works just fine, after you stopped them

over 1 year ago ·

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

In case of error message Get http:///var/run/docker.sock/v1.14/containers/json?all=1: dial unix /var/run/docker.sock: permission denied

over 1 year ago ·

I would add the -v flag:
docker rm -v $(docker ps -a -q)
else volumes will remain on the hard drive eating up space. Of course, be sure you want to delete your volumes and don't accidently delete data containers.

over 1 year ago ·

thanks!

over 1 year ago ·

Thanks! Fabulous!

over 1 year ago ·

To only stop exited containers and delete only non-tagged images.:
docker ps --filter 'status=Exited' -a | xargs docker stop docker images --filter "dangling=true" -q | xargs docker rmi

over 1 year ago ·

Thank you. Very helpful!

over 1 year ago ·

Remove all containers that aren't currently running:
docker rm $(docker ps -a -q -f "status=exited*")

over 1 year ago ·

For anyone having trouble make sure you sudo the 2nd docker command:

sudo docker rm -f $(sudo docker ps -a -q)

over 1 year ago ·

sudo docker rm -f -v $(sudo docker ps -a -q)

if not the volumes will not be delete !!! (like if you are using a mysql docker image)
and all the volumes will be orphans !

over 1 year ago ·

Just a reminder - this command cannot be used via ssh like this:
ssh server@127.0.0.1 "docker stop $(docker ps -a)"
Because $(docker ps -a) will be executed on your local machine, not on server.

over 1 year ago ·

The below removes all the Containers.

for f in docker ps -a -q; do docker rm $f; done

over 1 year ago ·

Helped me a lot, thanks =D

over 1 year ago ·

You can use this as a bash alias:
dstop() { docker stop $(docker ps -a -q); } alias dstop=dstop

over 1 year ago ·

With this, I can also delete the volume what container used to be mapped directly :) *if you didn't configure your local directory

Thanks man!!! I really appreciate it!!

over 1 year ago ·

Great Thanks

over 1 year ago ·

short and easy, thanks!

over 1 year ago ·

//remove all containers with keyword cluster
docker rm $(docker ps -a |grep cluster|awk '{print $1;}')

//remove all images with keyword cluster
docker rmi $(docker images |grep cluster|awk '{print $3;}')

over 1 year ago ·

If you want to stop them faster:

docker ps -a -q | xargs -n 1 -P 8 -I {} docker stop {}

over 1 year ago ·

With the latest docker 1.13, you can manage the container deletion in more efficient way. Check out this thread for the latest docker features for cleaning up images and containers http://discuss.devopscube.com/t/how-to-delete-all-none-untagged-and-dangling-docker-containers-and-images/23

over 1 year ago ·

thanks! good work

over 1 year ago ·

In Powershell, it's docker stop @(docker ps -a -q).

over 1 year ago ·

Also seems like this is a useful command to do cleanup:
docker volume prune

over 1 year ago ·

Why don't they just implement something like docker rm '*'?

over 1 year ago ·

Following worked for me on my mac. This is combination from 2 other responses.

alias stopall='docker ps -a -q | xargs -n 1 -P 8 -I {} docker stop {}'
alias removeall='docker ps -a -q | xargs -n 1 -P 8 -I {} docker rm {}'

over 1 year ago ·

search docker-clean github.com

over 1 year ago ·

working solution, easy and simple

over 1 year ago ·