0

I have set up private docker repository on my local centos machine and its working fine.

I have one project, which currently in build stage so many docker images with unique versions are getting created.

I want to keep the latest 3 docker images of that same repository and delete rest of the images of that project

How can I do that ?

Devendra
  • 185
  • 14
  • Simple bash script would do. Also by "version" you mean the tag right? There are no "versions" per se when in the context of Docker containers. – Mike Doe May 30 '19 at 11:24
  • the bash script will help you – Guru May 30 '19 at 11:31
  • @emix yes, I mean tags – Devendra May 30 '19 at 11:34
  • @Guru Can you please provide me an example for that? – Devendra May 30 '19 at 11:35
  • 1
    I would iterate over `docker images --filter "reference=your-app-tag-name" | tail -n +2`, sort the list, then pass the id to the `docker rmi` command. – Mike Doe May 30 '19 at 11:36
  • 1
    this can help you https://github.com/TranceMaster86/docker-reg-gc/blob/master/docker-reg-gc.sh – Adiii May 30 '19 at 12:08
  • @emix This is right, I am able to delete Docker images present on my server but unable to delete them from docker repository, Any solutions to that ? – Devendra May 30 '19 at 13:57
  • There are lots of threads on this topic already. – Mike Doe May 30 '19 at 17:49
  • yeah, I have tried **registry_cleaner.rb file method** and it runs on my local without an error also shows me logs that it removed the manifest but it won't delete any images on my docker private remote registry. `./registry_cleaner.rb --host=http://ssandbox.test.com:5000/ --repository=app --tags_count=1` I am using above command Ref: [https://github.com/oniksfly/registry_cleaner] – Devendra May 31 '19 at 07:12

0 Answers0