Loading...

Remove all exited docker images

:heavy_exclamation_mark: This post is older than a year. Consider some information might not be accurate anymore. :heavy_exclamation_mark:

Playing around with docker may leave a lot of exited images. A one-line command to cleanup your working environment. :-) Just use sudo docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs sudo docker rm. Remove the sudo if you are root.

A small demonstration:

tan@omega:~/Sources/improved-docker-elasticsearch$ sudo docker ps -a
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS                        PORTS               NAMES
23e8aac03da1        cinhtau/elasticsearch   "/docker-entrypoint.s"   9 minutes ago       Exited (130) 5 minutes ago                        prickly_stonebraker
a5ff8a4c917b        cinhtau/elasticsearch   "/docker-entrypoint.s"   9 minutes ago       Exited (130) 9 minutes ago                        vinh
0a4e13dcfe52        cinhtau/elasticsearch   "/docker-entrypoint.s"   11 minutes ago      Exited (130) 10 minutes ago                       suspicious_shaw
632aa3ff3e8f        cinhtau/elasticsearch   "/docker-entrypoint.s"   13 minutes ago      Exited (130) 12 minutes ago                       berserk_dijkstra
2f17d64ff7db        cinhtau/elasticsearch   "/docker-entrypoint.s"   17 minutes ago      Exited (130) 16 minutes ago                       tender_bohr
19345357c2af        cinhtau/elasticsearch   "/docker-entrypoint.s"   18 minutes ago      Exited (0) 17 minutes ago                         elated_brattain
00e077ac1d20        cinhtau/elasticsearch   "/docker-entrypoint.s"   22 minutes ago      Exited (130) 18 minutes ago                       desperate_goldstine
ddf3a8e382a9        cinhtau/elasticsearch   "/docker-entrypoint.s"   28 minutes ago      Exited (130) 27 minutes ago                       modest_davinci
a5ecec7eeeeb        cinhtau/elasticsearch   "/docker-entrypoint.s"   28 minutes ago      Exited (64) 28 minutes ago                        gloomy_lovelace
9dbdc789a006        hello-world             "/hello"                 5 weeks ago         Exited (0) 5 weeks ago                            tiny_pasteur

Remove it.

tan@omega:~/Sources/improved-docker-elasticsearch$ sudo docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs sudo docker rm
23e8aac03da1
a5ff8a4c917b
0a4e13dcfe52
632aa3ff3e8f
2f17d64ff7db
19345357c2af
00e077ac1d20
ddf3a8e382a9
a5ecec7eeeeb
9dbdc789a006

Check if everything is gone.

tan@omega:~/Sources/improved-docker-elasticsearch$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
Please remember the terms for blog comments.