zguz_w
Last Updated: February 12, 2019
·
97.76K
· filosottile

Docker: remove all Exited containers

A oneliner!

sudo docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs sudo docker rm

8 Responses
Add your response

20904

Love the simplicity of this :)

over 1 year ago ·
21124

docker rm $(docker ps -q -f status=exited)

over 1 year ago ·
21126

@vosmith

docker rm $(docker ps --all -q -f status=exited)

over 1 year ago ·
21130

@miraculixx

I don't think --all can be used with -f. Usually --all would display stopped/exited containers, but with -f status=exited, it already returns those. Please correct me if I'm wrong.

over 1 year ago ·
28923

Prefer using miraculixx command

over 1 year ago ·
30761

This change is a little more bulletproof, though I am generally a huge fan of using grep and cut, but when you are doing something that removes containers explicit is good.

This will avoid inadvertently removing any containers which happen to have the word Exit in the name or command, and won't stop working if the output format of "docker ps -a" ever changes.

docker ps -a --filter status=exited --format {{.ID}} | xargs docker rm

5 months ago ·
31004

IMHO
docker rm $(docker ps -qa --filter status=exited )

4 months ago ·