0

I have a private Docker registry, and I'm looking for a script (either shell or python) to delete images older than X Days. I found some examples but there are deleting all images except the latest tag which is not what I'm expecting.

Any help will be appreciated !

tiamat
  • 879
  • 2
  • 12
  • 35
  • if images are files, than file selection based on modification date can be done with 'find' or with some shell patterns – yvs2014 Jun 29 '23 at 11:56
  • How are you defining "older than X days"? Are you looking at the created time in the image config? Do you have multi-platform images? Do you care about when the image was pushed or last used? Do you need to preserve some number of images? – BMitch Jun 29 '23 at 12:24
  • My Docker Registry is installed on a Linux server, and each Images are generated automatically by our CI/CD which is using a tag naming different from "latest". As we are launching pipelines quite often, we would need to delete images older than 100 days as for sure there are not used anymore and it will help us to save memory ! – tiamat Jun 29 '23 at 12:35
  • This answer may help: https://stackoverflow.com/a/70464116/596285 – BMitch Jul 02 '23 at 19:25
  • A note of caution, if your private registry is `registry:2`, aka github.com/distribution/distribution, the included GC will delete too much if you have multi-platform images. For more details, see https://github.com/distribution/distribution/issues/3178 – BMitch Jul 02 '23 at 21:02

0 Answers0