Nebius Israel
Contact usConsole
  • GPU
  • Docs
© 2023 Nebius Israel Ltd
Container Registry
  • Getting started
  • Container Solution
  • Access management
  • Pricing policy
  • Troubleshooting
  • Questions and answers
  1. Step-by-step guides
  2. Managing Docker image lifecycle policies
  3. Updating a lifecycle policy

Updating a lifecycle policy

  • Examples
    • Updating lifecycle policy rules
    • Updating a lifecycle policy status
    • Updating a lifecycle policy name
    • Updating a lifecycle policy description

Once you create a lifecycle policy, you can modify its rules as well as its status, name, or description.

Management console
CLI
Terraform
API
  1. In the management console, select the folder where the registry was created.
  2. In the list of services, select Container Registry.
  3. Select the registry and click the row with its name.
  4. Select the repository and click the row with its name.
  5. In the left-hand panel, click Lifecycle.
  6. In the row with the lifecycle policy you need, click and select Edit.
  7. Edit the lifecycle policy parameters:
    • Name.

    • Description.

    • Status.

    • Under Lifecycle policy rules, update the rule parameters:

      • Tag: Docker image tag for filtering. Java regular expressions are supported. For example, the test.* regular expression retrieves all images with tags starting with test.
      • Untagged: Flag indicating that the rule applies to Docker images without tags.
      • Expire period, in days: Time after which the lifecycle policy may apply to the Docker image.
      • Retained top: Number of Docker images that are not deleted even if they match the rule.
    • Description.

  8. Click Create.

If you don't have the Nebius Israel command line interface yet, install and initialize it.

  1. See the description of the CLI command for updating policy parameters:

    yc container repository lifecycle-policy update --help
    
  2. Change the policy parameters, such as by renaming it:

    yc container repository lifecycle-policy update <policy ID> \
      --new-name=new-policy
    

    To find out the policy ID, get a list of lifecycle policies in a repository or registry.

If you do not have Terraform yet, install it and configure the Nebius Israel provider.

  1. Open the configuration file and edit the fragment with the policy description:

    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"
      }
    }
    
  2. Apply the changes:

    1. In the terminal, change to the folder where you edited the configuration file.

    2. Make sure the configuration file is correct using the command:

      terraform validate
      

      If the configuration is correct, the following message is returned:

      Success! The configuration is valid.
      
    3. Run the command:

      terraform plan
      

      The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.

    4. Apply the configuration changes:

      terraform apply
      
    5. Confirm the changes: type yes in the terminal and press Enter.

This will update the lifecycle policy in the specified repository. You can check that the policy is updated using the management console or this CLI command:

 yc container repository lifecycle-policy list --registry-id <registry_ID>

To edit a lifecycle policy, use the Update method for the LifecyclePolicyService resource. Specify the policy ID in the lifecycle_policy_id property.

You can retrieve a list of policies using the List method for the LifecyclePolicyService resource.

ExamplesExamples

Updating lifecycle policy rulesUpdating lifecycle policy rules

CLI
  1. Prepare 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, the test.* regular expression retrieves all images with tags starting with test.
    • untagged: Flag indicating that the rule applies to Docker images without tags.
    • expire_period: Time after which the lifecycle policy may apply to the Docker image. This parameter is formatted as a number and a unit of measure, such as s, m, h, or d (seconds, minutes, hours, or days). expire_period must be a multiple of 24 hours.
    • retained_top: Number of Docker images that are not 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"
      }
    ]
    
  2. Change the policy rules by running the command with the following parameter:

    • new-rules: Path to the file with the new policy description.

    Alert

    Updating the policy completely overwrites all current rules by destroying them.

    yc container repository lifecycle-policy update crp6lg1868p3i0emkv1b --new-rules ./new-rules.json
    

    Result:

    WARN: All current lifecycle rules will be overwritten. Are you sure?[y/N] y
    id: crp6lg1868p3i0emkv1b
    name: test-policy
    ...
      expire_period: 172800s
      tag_regexp: test.*
      untagged: true
    

Updating a lifecycle policy statusUpdating a lifecycle policy status

Activate a lifecycle policyActivate a lifecycle policy

CLI

Activate a deactivated lifecycle policy by running the command below with the --activate flag:

yc container repository lifecycle-policy update crp6lg1868p3i0emkv1b --activate

Result:

id: crp6lg1868p3i0emkv1b
name: test-policy
repository_id: crp3cpm16edqql0t30s2
...
  expire_period: 172800s
  tag_regexp: test.*
  untagged: true

Disable a lifecycle policyDisable a lifecycle policy

CLI

Deactivate an active policy by running the command below with the --disable flag:

yc container repository lifecycle-policy update crp6lg1868p3i0emkv1b --disable

Result:

id: crp6lg1868p3i0emkv1b
name: test-policy
repository_id: crp3cpm16edqql0t30s2
...
  expire_period: 172800s
  tag_regexp: test.*
  untagged: true

Updating a lifecycle policy nameUpdating a lifecycle policy name

CLI

Change the policy name by running the command:

yc container repository lifecycle-policy update crp6lg1868p3i0emkv1b --new-name new-policy

Where new-name is the new policy name.

  • The length can be from 3 to 63 characters.
  • It may contain lowercase Latin letters, numbers, and hyphens.
  • The first character must be a letter. The last character can't be a hyphen.

Result:

id: crp6lg1868p3i0emkv1b
name: new-policy
repository_id: crp3cpm16edqql0t30s2
...
  expire_period: 172800s
  tag_regexp: test.*
  untagged: true

Updating a lifecycle policy descriptionUpdating a lifecycle policy description

CLI

Change the policy description by running the command:

yc container repository lifecycle-policy update crp6lg1868p3i0emkv1b --new-description "new description"

Where new-description: New policy description.

Result:

id: crp6lg1868p3i0emkv1b
name: test-policy
repository_id: crp3cpm16edqql0t30s2
...
  expire_period: 172800s
  tag_regexp: test.*
  untagged: true
© 2023 Nebius Israel Ltd
In this article:
  • Examples
  • Updating lifecycle policy rules
  • Updating a lifecycle policy status
  • Updating a lifecycle policy name
  • Updating a lifecycle policy description