Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove old Docker images based on past usage

Tags:

docker

I know how to remove old Docker images created more that N days ago. See here
But what I'd really like to do is to remove old Docker images that were not used for the last N days.
The goal is to keep images that are frequently used, even if no container is actually using them when I do the cleanup.
Is this possible?

like image 992
Jean-François Larvoire Avatar asked Oct 18 '25 06:10

Jean-François Larvoire


1 Answers

This is not trivial because docker doesn't track usage timestamps, only creation. So the builtin commands can't make decisions based on usage.

An old but periodically active ticket to address this is https://github.com/moby/moby/issues/4237

I'm aware of two separate programs which attempt to address this, both monitor the docker events stream to create their own log of container usage.

docuum keeps the disk usage to a set limit, deleting the oldest image by usage if that limit is exceeded https://github.com/stepchowfun/docuum

docker-gc deletes any image that hasn't been used in X time. When the docker-gc documentation refers to age it means time since last used https://github.com/docwhat/docker-gc

like image 105
lod Avatar answered Oct 21 '25 01:10

lod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!