ewk0mq
Last Updated: October 11, 2018
·
911.1K
· 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)

28 Responses
Add your response

12306

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

over 1 year ago ·
13949

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

over 1 year ago ·
14638

great command!

over 1 year ago ·
15944

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 ·
16366

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

works just fine, after you stopped them

over 1 year ago ·
16367

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

works just fine, after you stopped them

over 1 year ago ·
16400

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 ·
17010

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 ·
17094

thanks!

over 1 year ago ·
17404

Thanks! Fabulous!

over 1 year ago ·
17600

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 ·
18015

Thank you. Very helpful!

over 1 year ago ·
20852

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

over 1 year ago ·
21127

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 ·
22647

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 ·
22847

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 ·
23444

The below removes all the Containers.

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

over 1 year ago ·
23848

Helped me a lot, thanks =D

over 1 year ago ·
24967

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

over 1 year ago ·
27631

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 ·
27677

Great Thanks

over 1 year ago ·
28131

short and easy, thanks!

over 1 year ago ·
28153

//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 ·
28521

If you want to stop them faster:

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

over 1 year ago ·
28559

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 ·
29475

thanks! good work

11 months ago ·
30007

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

4 months ago ·
30037

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

4 months ago ·