- What's new
- Function Overview
- Service Overview
- Getting Started
-
User Guide
- Introduction
- Permissions Management
- Basics of the Container Engine
-
Image Management
- Uploading an Image Through a Container Engine Client (Recommended)
- Obtaining a Long-Term Valid Login Command
- Uploading an Image Through SWR Console
- Pulling an Image
- Setting Image Attributes
- Sharing a Private Image
- Adding a Trigger
- Adding an Image Retention Policy
- Configuring Automatic Image Synchronization Between Regions
- Image Center
- Organization Management
- User Permissions
- Auditing
- Change History
- Best Practices
-
API Reference
- Before You Start
- Calling APIs
- API Overview
-
API
- Organization Management
- Managing Image Repositories
- Image Tag Management
- Shared Account Management
- API Version
- Organization Permission Management
- Image Permission Management
- Image Synchronization Management
- Trigger Management
- Image Retention Policy Management
- Temporary Login Command
- Quota Management
- Other
- Example Applications
- Appendixes
- SDK Reference
-
FAQs
- General FAQs
- Login Issues
- Synchronizing Images
- Pushing an Image
- Pulling an Image
-
Troubleshooting
- Why Does the Login Command Fail to Be Executed?
- Why Does an Image Fail to Be Pushed Through a Container Engine Client?
- Why Does an Image Fail to Be Uploaded Through SWR Console?
- Why Does the docker pull Command Fail to Be Executed?
- What Should I Do If Images Cannot Be Downloaded from Private Networks?
- What Do I Do If an Error Occurs When I Call an API?
-
Other FAQs
- Why Does a CCE Workload Cannot Pull an Image from SWR and a Message "Not Logged In" Is Displayed?
- How Many Tenants Can I Share an SWR Private Image With?
- Why Is an Image Pushed Using a Container Engine Client to SWR Different in Size From One Uploaded Through the SWR Console?
- Can I Pull Images on the SWR Console to a Local PC?
- Videos
- Glossary
-
More Documents
- User Guide
- API Reference
- User Guide (Paris Regions)
- API Reference (Paris Regions)
- User Guide (Kuala Lumpur Region)
- API Reference (Kuala Lumpur Region)
-
User Guide (Ankara Region)
- Service Overview
- Overview
- Permissions Management
- Basics of Docker
-
Image Management
- Pushing an Image Through a Container Engine Client
- Obtaining a Long-Term Valid Docker Login Command
- Obtaining a Long-Term Valid containerd Pull/Push Command
- Uploading an Image Through the SWR Console
- Pulling an Image
- Setting Image Attributes
- Sharing Private Images
- Adding a Trigger
- Adding an Image Retention Policy
- Organization Management
- User Permissions
- FAQs
-
API Reference (Ankara Region)
- Before You Start
- API Overview
- Calling APIs
- API
- Appendixes
- Permissions and Supported Actions
- General Reference
Copied.
Adding an Image Retention Policy
Scenario
You can add a retention policy to an image in SWR to automatically delete any unused image tags. The policy takes effect immediately after you set it. There are two types of policies:
- Number of days: keeping only image tags that have been pushed to SWR within a certain number of days.
- Number of tags: keeping only a certain number of the most recent image tags.
You can configure filters for your retention policy to prevent certain image tags from being affected by the retention policy.
Notes and Constraints
Only one retention rule can be added to an image. If you want to add a new retention policy, you must delete the existing policy.
Procedure
- Log in to the SWR console.
- In the navigation pane on the left, choose My Images, and click the desired image to enter its details page.
- On the Retention tab page, click Add Retention Policy. Configure the policy based on Table 1 and click OK.
Figure 1 Adding a retention policy
Table 1 Parameters for adding an image retention policy Parameter
Description
Policy Type
There are two types of retention policies:
- Number of days: keeping only image tags that have been pushed to SWR within a certain number of days.
- Number of tags: keeping only a certain number of the most recent image tags.
Count Limit (Number of days)
When you set Policy Type to Number of days, the value of Count Limit indicates the maximum number of the most recent image tags to be retained. The value should be an integer ranging from 1 to 365.
Count Limit (Number of tags)
When you set Policy Type to Number of tags, the value of Count Limit indicates the maximum number of the most recent image tags to be retained. The value should be an integer ranging from 1 to 1,000.
Tag Filter
Enter image tags that you do not want this retention policy to apply to.
Regular Expression Filter
Enter a regular expression. Image tags meeting this regular expression will not be affected by this retention policy.
After the retention policy is added, SWR immediately applies the policy and displays deleted image tags (if any) in the Retention Logs area.
Figure 2 Checking the retention policy and logs
Example 1: Set Policy Type to Number of Days
The update time of Nginx v1 image and Nginx v2 image is shown in the following figure.
![Click to enlarge](https://support.huaweicloud.com/intl/en-us/usermanual-swr/en-us_image_0000001152095130.png)
- Add a retention policy.
Set Policy Type to Number of days, and Count Limit to 3.
Figure 4 Adding a retention policy - Check whether the retention policy has taken effect.
Check Retention Logs. Nginx v1 image has been stored for more than three days (the current time is 2021/09/01 16:00:00). Therefore, it is automatically removed.
Check Image Tag. Only Nginx v2 image is left.
Figure 5 Image tag v2The retention policy has taken effect.
Example 2: Set Policy Type to Number of Tags, and Specify Regular Expression Filter
Click Image Tags tab page. Nginx v1 image, Nginx v2 image, Nginx v1.0.0 image and Nginx v2.0.0 image are shown in Image tags.
![Click to enlarge](https://support.huaweicloud.com/intl/en-us/usermanual-swr/en-us_image_0000001151939988.png)
- Add a retention policy.
Set Policy Type to Number of tags, Count Limit to 1, and Regular Expression Filter to ^v2.*.
Figure 7 Adding a retention policy - Check whether the retention policy has taken effect.
Before the retention policy takes effect, Nginx v2 image and Nginx v2.0.0 image are filtered for matching the regular expression. Only one of Nginx v1 image and Nginx v1.0.0 image will be stored. Nginx v1 image will be removed because it is older.
Check Retention Logs and Image Tag. If Nginx v1 image is removed, the retention policy has taken effect.
Figure 8 Image tagsThe following regular expressions are for your reference:
- ^[0-9]*$: filters out tags consisting of numbers.
- ^.{2,5}$: filters out tags with a length ranging from 2 to 5 characters.
- ^[a-z]+$: filters out tags consisting of lowercase letters.
- ^[A-Za-z0-9]+$: filters out tags consisting of letters and numbers.
CAUTION:
If there is an OR (|) operator in a regular expression, enclose the OR part in parentheses, or the regular expression will be parsed incorrectly and all tags of the image will be removed.
For example, if you only want to retain tags containing a or s, the regular should be (.*a.*|.*s.*).
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot