Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (23 sloc) 1.85 KB

Remove orphaned images

I found this tip here: https://forums.docker.com/t/how-do-i-remove-orphaned-images/1172

Orphaned images are untagged images that do not have any tagged offspring. You can find these images using the command docker images -f dangling=true.

Note: Data volumes that are not attached to a running container will look like orphaned images. If you remove all orphaned images, then you may be destroying data volumes that you meant to keep. Be careful. And make sure you have backups of everything you care about before proceeding.

You can remove orphaned images using this bash command:

docker rmi $(docker images -f dangling=true -q)

Update ... nice cleanup function

(Update 2016-12-04T14:48:43-0600.)

I found a nice Bash function that first blows away stopped containers and then removes dangling images.

# found this nice image/container cleanup script here:
# http://stackoverflow.com/a/32723127/1392864
#
dkr_cleanup_unused() {
  docker rm -v $( docker ps --filter status=exited -q 2> /dev/null ) 2> /dev/null
  docker rmi $( docker images --filter dangling=true -q 2> /dev/null ) 2> /dev/null
}

© 2016 Dave Hein

Creative Commons License
This work by Dave Hein is licensed under a Creative Commons Attribution 4.0 International License.