Keeping your Docker environment clean
First, we want to learn how we can delete dangling images. A dangling Docker image is an unused image that has no association with any tagged images or containers. It usually occurs when a new image is built using the same tag as an existing image. Instead of removing the old image, Docker preserves it but removes the tag reference, leaving the image without a proper tag.
Dangling images are not referenced by any container or tagged image, and they consume disk space without providing any benefit. They can accumulate over time, especially in environments with frequent image builds and updates. Thus, it is better to remove them from time to time. Here is the command to do so:
$ docker image prune -f
Please note that we have added the -f
(or --force
) parameter to the prune
command. This is to prevent the CLI from asking you to confirm that you really want to delete those superfluous layers.
Stopped containers can waste precious resources...