Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker prune images not used in the last X hours

Is there a way to do docker prune image to get rid of images if either they or their intermediary layers have not been used in the last X hours?

The purpose is: Say a build has created intermdiary and final image(F1). A subsequent build can use the intermediary image. While this subsequent build is running, if I run docker image prune -f -a in another window, then Docker will delete the image F1 (assuming it is unused) and it's intermediary images. Thus the build in progress even if it had used intermediary image will have to rebuild the intermediary image. If there is a filter setting on the prune command based on last used then it will be helpful.

like image 556
variable Avatar asked Sep 15 '25 18:09

variable


1 Answers

Based on "last used" it might not be very easy, there is still issue going on: https://github.com/moby/moby/issues/4237

Tool named 'docuum' is created for it if you are ready to use it. Also less maintained docker-gc is available.

You can prune based on "last created" as hours for example:

docker image prune -a --force --filter "until=5h"

Source: https://docs.docker.com/engine/reference/commandline/image_prune/

like image 88
Niklas Avatar answered Sep 17 '25 11:09

Niklas