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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With