No doubt we’ve all seen the messages from Docker Hub stating they’ll start deleting “inactive images” after X months… clearly the cost of storing all these images is starting to bite, and understandably, the administrators of the Docker Hub service are looking at ways to free up that data.
I’d like to help them in that. My workplace uses Docker with a CI/CD system, and regularly pushes out new builds under a
latest is used for the latest
master-branch build. These tags are essentially “overwritten”: a new image is tagged with that tag, and that tagged image is then pushed over the top of the old one.
We also generate temporary tags for things like feature and bugfix branches, as well as tags for each version-numbered release of an image. We don’t need to keep these forever, but while
docker rmi will remove the image locally, there’s seemingly no
docker unpush (for want of a better name) to remove an image (tagged or otherwise) from the remote repository. Thus I’m unable to remove those temporary tags from the image repository, and they languish until I can come along from the Docker Hub UI and delete them manually.
Furthermore, I had thought once that was done, good, old image is gone.
docker pull me/myrepo:tag pulls the new image and not the old one. Turns out, they still keep the old image around for reasons I do not understand (since you can’t pull them via the old tag name). This compounds the problem, since images I thought would be deleted due to being inaccessible, are still kept.
That is needlessly costing Docker money. It’d theoretically be no skin of my nose to write a CLI wrapper around the
docker command to clean up those images.
docker <something> ls untagged | xargs docker <something> rm… and maybe some sort of clean-up task to take care of stale feature/bugfix branch tags.
The blocker to doing this is I don’t know what the
<something> is that goes after the
docker command that tells
docker to do the action on the Docker Hub repo. What do I put here to make
docker do this? Why doesn’t
docker help /
man docker describe this?