ARTIFACTORY: How to Delete Old Docker Images

Pradnya Shinde
2023-01-22 11:10

To delete Docker images that are older than a certain date, do the following:
Docker image layers are stored as separate artifacts within an image folder. Accordingly, to delete old Docker images, you’ll first want to search for your manifest.json file in your Docker images folder by doing the following:

  1. Using Artifactory Query Language (AQL), get a manifest.json list containing those files that are older than a given date. For example, you can use the following manifest.json to return a list of files that are four (4)-weeks old and over:

items.find({“name”:{“$eq”:”manifest.json”},”stat.downloaded”:{“$before”:”4w”}})

Note: This will also return the repo and path in the search results.

  1. To delete images, you can use the:

  • Delete Item REST API to delete the Docker image associated with a particular path returned in your AQL search results. However, if a layer is shared between two different images, but only one is a candidate for deletion, then that layer will not be deleted from your binary storage because it’s still being referenced by the other image.

  • Artifactory Clean Docker Images user plugin

Information about Limiting Unique Docker Tags and Limiting the Number of Snapshots is available HERE and HERE, respectively.

Published: Feb. 3, 2020
Last updated: Feb. 24, 2021

Keywords: delete old Docker images, Docker tags