dockerdocker-image

What is a dangling image and what is an unused image?


In the docker documentation of docker image prune it is possible to use the -a flag to

Remove all unused images, not just dangling ones

and later

Remove all dangling images. If -a is specified, will also remove all images not referenced by any container.

Q: What are dangling images?
Q: What's the difference between dangling and unused images?


Solution

  • An unused image means that it has not been assigned or used in a container. For example, when running docker ps -a - it will list all of your exited and currently running containers. Any images shown being used inside any of containers are a "used image".

    On the other hand, a dangling image just means that you've created the new build of the image, but it wasn't given a new name. So the old images you have becomes the "dangling image". Those old image are the ones that are untagged and displays "<none>" on its name when you run docker images.

    When running docker system prune -a, it will remove all stopped containers, images and networks without a container associated, and build cache. Be Careful!