While checking my Docker images through UGOS, I noticed several entries that appear to be duplicates. The green image is currently running, the gray image seems to be an older version, and the red entries are untagged versions left behind after updates. Are the red images safe to remove, and can the older gray image be deleted too? I want to clean things up without affecting the running container or losing an easy rollback option.
3 Answers
The safest way to check is to look at all containers, including stopped ones, because they can still reference an image: `docker ps -a --format '{{.Image}} {{.Status}}' | sort -u`. For basic cleanup, `docker image prune` removes only untagged dangling images. `docker image prune -a` is more aggressive and removes any image that no container references. The older gray image may still be useful as a rollback if the newest version has a problem, so I usually keep one previous version and remove the rest.
The red entries labeled are usually older image versions that lost their tags when a newer image was pulled. That is normal and not necessarily an error. Docker also will not remove an image if a container still references it, so you cannot accidentally delete the image used by a running container.
If your update process does not clean up old images, you can run a cleanup command after updating your compose projects. For example, `docker image prune -f` removes dangling images without prompting. Just be more careful with `docker image prune -a`, since it can remove unreferenced images that you may want for a quick rollback.

So the green image is considered in use, while an old red or gray image would only be removable if no container references it? If Docker refuses the deletion, that means something still depends on it?