How can I delete Docker images older than a certain time period?

Pradnya Shinde
2019-07-09 17:00

Summary

How to delete Docker images older than a certain time period?

Instructions

This is the process you can follow for deleting the Docker tags older than a certain date:

  1. Using AQL: get the list of manifest.json which are older than a certain time period
  2. For example, you can use this to return the list of manifest.json that are 4 weeks old or more: 
  • items.find({"name":{"$eq":"manifest.json"},"stat.downloaded":{"$before":"4w"}})
    • Note: this will also return the repo and path in the search result.
  1. Then using this REST API you can delete the Docker tag at that particular path that was returned above in the search result
  • If a layer is shared between two different tags and if one of the tag is a candidate for the delete in your case above, then the layer will NOT be deleted in the binary storage since it will be still referenced by the other tag.

Other relevant references:

Limiting Unique Docker Tags
Max Unique Snapshots