garbage collecting docker images - benclifford/text GitHub Wiki
How to know when an image is unneeded?
We have this flat space of images (with image IDs).
In garbage collection, we have roots, and anything referred to transitively by a root is kept, and everything that isn't is not.
Initially, if you rmi every image, images in use by a container (running or stopped) are not removed by docker. So each container is a root.
But what about if we're using some images for (e.g) build tooling that only runs occasionally (for example on every CI build) and for which there is usually (in quiescent state) no container. How do we add roots for that?
In some projects, I've tagged important images with docker tag, and not removed those. But tags "rot" - maybe they're for a project no longer needed.
More recently, I've been using "local" tagging - generate an image, get its image ID, and store that in a file in your local workspace. That provides some properties like being able to have multiple workspaces, with their relevant images separately identified. compared to using "global" tag space. but that means I can't garbage collect based on global tags any more.
related approaches for local-workspace-stuff: store a docker save export of the image. if we want a named image and it is not in docker already but we have the local save, restore it. I haven't tried this.