Updating a lifecycle policy
Warning
Starting October 13, 2026, Yandex Container Registry will be unavailable to new users.
The existing users can create resources until November 10, 2026. Afterwards, Yandex Container Registry will go read-only and cease to operate on December 14, 2026. For more information on how it will be handled, see this article on Yandex Container Registry sunset.
After you create a lifecycle policy, you can edit its rules as well as its status, name, or description.
- In the management console
, select the folder with the registry. - Navigate
to Container Registry. - Select the registry and click the row with its name.
- Select the repository and click the row with its name.
- In the left-hand panel, click
Lifecycle. - In the lifecycle policy row, click
and select Edit. - Edit the lifecycle policy settings:
-
Name.
-
Description.
-
Status.
-
Under Lifecycle policy rules, update the rule settings:
- Tag regexp: Docker image tag for filtering. Java regular expressions are supported. For example, the
test.*regular expression retrieves all images with tags starting withtest. - Untagged: Flag to apply the rule to untagged Docker images.
- Expire period, in days: Time after which the lifecycle policy may apply to the Docker image.
- Retained top: Number of Docker images that will not be deleted even if they match the rule.
- Description.
- Tag regexp: Docker image tag for filtering. Java regular expressions are supported. For example, the
-
- Click Save.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
-
See the description of the CLI command for updating policy settings:
yc container repository lifecycle-policy update --help -
Update the policy settings, e.g., rename the policy:
yc container repository lifecycle-policy update <policy_ID> \ --new-name=new-policyTo find out the policy ID, get a list of lifecycle policies in the repository or registry.
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), authenticate using the appropriate method.
-
Open the configuration file and edit the section describing the policy:
resource "yandex_container_repository_lifecycle_policy" "my_lifecycle_policy" { name = "best-policy" status = "active" repository_id = "crpfvi6o4ra7********" rule { description = "rule for applying policy" untagged = true tag_regexp = ".*" retained_top = 1 expire_period = "48h" } } -
Apply the changes:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
-
This will update the lifecycle policy in the specified repository. You can check the policy update using the management console
yc container repository lifecycle-policy list --registry-id <registry_ID>
To update a lifecycle policy, use the Update method for the LifecyclePolicyService resource. Specify the policy ID in the lifecycle_policy_id property.
You can get the list of policies using the List method for the LifecyclePolicyService resource.
Examples
Updating lifecycle policy rules
-
Create new policy rules and save them to a file named
new-rules.json.Example of the contents of a file with rules, where:
description: Description of the policy rule.tag_regexp: Docker image tag for filtering. Java regular expressions are supported. For example, thetest.*regular expression retrieves all images with tags starting withtest.untagged: Flag to apply the rule to untagged Docker images.expire_period: Time after which the lifecycle policy may apply to the Docker image. This parameter comes as a number followed by a unit of measurement:s,m,h, ord(seconds, minutes, hours, or days).expire_periodmust be a multiple of 24 hours.retained_top: Number of Docker images that will not be deleted even if they match the rule.
[ { "description": "delete prod Docker images older than 60 days but retain 20 last ones", "tag_regexp": "prod", "expire_period": "60d", "retained_top": 20 }, { "description": "delete all test Docker images except 10 last ones", "tag_regexp": "test.*", "retained_top": 10 }, { "description": "delete all untagged Docker images older than 48 hours", "untagged": true, "expire_period": "48h" } ] -
Update the current policy rules by running the command with the following parameter:
new-rules: Path to the file with the new policy description.
Alert
When you update the policy, all current rules are overwritten and deleted.
yc container repository lifecycle-policy update crp6lg1868p3******** --new-rules ./new-rules.jsonResult:
WARN: All current lifecycle rules will be overwritten. Are you sure?[y/N] y id: crp6lg1868p3******** name: test-policy ... expire_period: 172800s tag_regexp: test.* untagged: true
Updating a lifecycle policy status
Activating a lifecycle policy
To activate a disabled policy, run the command below with the --activate flag:
yc container repository lifecycle-policy update crp6lg1868p3******** --activate
Result:
id: crp6lg1868p3********
name: test-policy
repository_id: crp3cpm16edq********
...
expire_period: 172800s
tag_regexp: test.*
untagged: true
Disabling a lifecycle policy
To disable an active policy, run the command below with the --disable flag:
yc container repository lifecycle-policy update crp6lg1868p3******** --disable
Result:
id: crp6lg1868p3********
name: test-policy
repository_id: crp3cpm16edq********
...
expire_period: 172800s
tag_regexp: test.*
untagged: true
Updating a lifecycle policy name
Update the policy name by running this command:
yc container repository lifecycle-policy update crp6lg1868p3******** --new-name new-policy
Where --new-name is the new policy name. The naming requirements are as follows:
- Length: between 3 and 63 characters.
- It can only contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with a hyphen.
Result:
id: crp6lg1868p3********
name: new-policy
repository_id: crp3cpm16edq********
...
expire_period: 172800s
tag_regexp: test.*
untagged: true
Updating a lifecycle policy description
Update the policy description by running this command:
yc container repository lifecycle-policy update crp6lg1868p3******** --new-description "new description"
Where --new-description is the new policy description.
Result:
id: crp6lg1868p3********
name: test-policy
repository_id: crp3cpm16edq********
...
expire_period: 172800s
tag_regexp: test.*
untagged: true