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.