Deleting (both tagged and untagged) images from Docker Hub from CLI

Hi all,

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 develop tag. 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?

The Docker CLI does not depend on the registry you are using. If you want to work with Docker Hub from command line, use the Hub Tool

It is part of Docker desktop but you can install hub-tool without that too.

hub-tool tag rm REPOSITORY:TAG

is to delete image tags. I think you don’t need to delete the images without tags, because those can be garbage collected or kept for other images that was based on yours.

I am not sure I understand. Do you mean you deleted an image with a tag and you could still pull that? If this is what happaned, the reason could be a delay. Sometimes you delete for example a repository and when you reload the page the repository seems to be there again. Some minutes later it disappears. I don’t know if it is regular. It happened only once to me and only when I tested it to answer a question.

1 Like

Right, so for actual image maintenance in a remote repository, we use hub-tool… is there an apt repository that ships this for Debian/Ubuntu systems?

I don’t know about that, but you can just download the latest release from the release page: