October 9, 2019 By Alex Parker 3 min read

Retention policies help keep your registry namespaces in check by retaining only the images that are important to you.

IBM Cloud Container Registry now offers retention policies that allow you to choose a number of images to retain in each repository in a namespace in order to decrease clutter, help meet storage quotas, and minimize storage costs.

When following continuous delivery practices, customers frequently push new images to their registry namespaces. Over time, the registry stores many images, though few may be needed or deployed anymore. 

With retention policies, you can select a number of images to be retained for each repository in a given namespace, and all other images in that namespace will be deleted. The newest images will be retained, with age determined by an image’s creation date. This action can be performed once to do a quick cleanup, or it can be scheduled to run daily to continuously delete images that are outside your policy settings.

Setting retention policies in the CLI

For example, the retention-test namespace has two repositories—mysql and mongo—that each contain three images:

To set a retention policy, use the ibmcloud cr retention-policy-set command, which takes a number of images and a namespace as arguments. When setting a retention policy, the policy takes effect immediately—meaning images will be deleted right away to fulfill your policy—and is also scheduled as a daily recurrence. The images that will be deleted are displayed, and a confirmation asks if you want to continue. 

In this example, two images will be retained per repository, which means that one image from each repository will be deleted at this time:

You can list your retention policies with the ibmcloud cr retention-policy-list command. Note that the default policy is to retain all images, so every namespace in your account will display in this list:

Since scheduled retention policies will automatically delete images in order to meet the policy’s specifications, a trash was implemented to hold deleted images for 30 days after their deletion in case they need to be restored. Any deleted images—not just those deleted by retention policies—initially move to the trash. You can view your trash with the ibmcloud cr trash-list command:

Images in the trash cannot be pulled, but they can be restored to the registry with the ibmcloud cr image-restore command.

If you simply want to perform a quick cleanup without setting a recurring policy, use the ibmcloud cr retention-run command in the same fashion.

Currently, retention policies are only supported in the CLI, but UI support is on the way. Additionally, future releases will allow finer-grained control of retention policies so that images can be deleted based on criteria other than creation date.

Learn more

Read more about retention policies in the documentation, and update your container-registry CLI plug-in to give it a try today.

More from Announcements

Success and recognition of IBM offerings in G2 Summer Reports  

2 min read - IBM offerings were featured in over 1,365 unique G2 reports, earning over 230 Leader badges across various categories.   This recognition is important to showcase our leading products and also to provide the unbiased validation our buyers seek. According to the 2024 G2 Software Buyer Behavior Report, “When researching software, buyers are most likely to trust information from people with similar roles and challenges, and they value transparency above other factors.”  With over 90 million visitors each year and hosting more than 2.6…

Manage the routing of your observability log and event data 

4 min read - Comprehensive environments include many sources of observable data to be aggregated and then analyzed for infrastructure and app performance management. Connecting and aggregating the data sources to observability tools need to be flexible. Some use cases might require all data to be aggregated into one common location while others have narrowed scope. Optimizing where observability data is processed enables businesses to maximize insights while managing to cost, compliance and data residency objectives.  As announced on 29 March 2024, IBM Cloud® released its next-gen observability…

Unify and share data across Netezza and watsonx.data for new generative AI applications

3 min read - In today's data and AI-driven world, organizations are generating vast amounts of data from various sources. The ability to extract value from AI initiatives relies heavily on the availability and quality of an enterprise's underlying data. In order to unlock the full potential of data for AI, organizations must be able to effectively navigate their complex IT landscapes across the hybrid cloud.   At this year’s IBM Think conference in Boston, we announced the new capabilities of IBM watsonx.data, an open…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters