ewk0mq
Last Updated: January 21, 2017
·
353.2K
· fgrehm
A198addd98dd9f149c7964a1340c9772

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)

24 Responses
Add your response

12306
0527b2b8a42471f06815891e5bfae7be

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

over 1 year ago ·
13949
D1a1261c915ba4b14e6ac382385de0f4

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

over 1 year ago ·
14638
F6876277bf54d7fb7063135b20557f59

great command!

over 1 year ago ·
15944
Fc2a414290d79b44f253539bb85d03c7

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
A486c31326dffba0cde8bade19108dc2

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

works just fine, after you stopped them

over 1 year ago ·
16367
A486c31326dffba0cde8bade19108dc2

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

works just fine, after you stopped them

over 1 year ago ·
16400
D4a047c06e2b4c028ba3346142e15b18

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
0 ebp1xfq jdikaawnxrauxsbigeo6pthnhzbuxuv c7o9u9096l 0e23spxyjrvdswnldiibqdz9j

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
Acf93279ad98c7df6fddf5187da3adfd

thanks!

over 1 year ago ·
17404
None

Thanks! Fabulous!

over 1 year ago ·
17600
None

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
P4130046 normal

Thank you. Very helpful!

over 1 year ago ·
20852
 bvnkwfl normal

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

over 1 year ago ·
21127
None

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
None

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
78c1a2b076379c57fd6dafc9b5928ea8

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
None

The below removes all the Containers.

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

over 1 year ago ·
23848
None

Helped me a lot, thanks =D

over 1 year ago ·
24967
A6fd013d05fbd7754009b0a83e3f3f09

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

over 1 year ago ·
27631
Iqbal1

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!!

8 months ago ·
27677

Great Thanks

8 months ago ·
28131

short and easy, thanks!

5 months 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;}')

4 months ago ·
28521

If you want to stop them faster:

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

4 days ago ·
Filed Under