Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
© 2022 Yandex.Cloud LLC
Yandex Container Registry
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Authentication in Container Registry
    • Managing a Docker image
      • Getting information about available Docker images
      • Creating a Docker image
      • Pushing a Docker image to a registry
      • Pulling a Docker image from a registry
      • Deleting a Docker image from a registry
    • Managing Helm charts
      • Getting information about available Helm charts
      • Pushing a Helm chart to a registry
      • Pulling a Helm chart from a registry
      • Deleting a Helm chart from a registry
    • Managing a registry
      • Getting information about existing registries
      • Creating a registry
      • Updating a registry
      • Deleting a registry
    • Managing a repository
      • Getting information about existing repositories
      • Creating a repository
    • Managing Docker image lifecycle policies
      • Getting information about existing lifecycle policies
      • Creating a lifecycle policy
      • Updating a lifecycle policy
      • Performing lifecycle policy dry runs
      • Deleting a lifecycle policy
    • Scanning Docker images for vulnerabilities
    • Working with roles
      • Assigning a role
      • Viewing assigned roles
      • Revoking a role
  • Yandex Container Solution
  • Practical guidelines
    • All tutorials
    • Running a Docker image on a VM
    • Creating a trigger with Yandex Cloud Functions
    • Setting up automatic scanning of a Docker image
  • Concepts
    • Overview
    • Docker image
    • Docker volume
    • Registry
    • Repository
    • Docker image lifecycle policies
    • Vulnerability scanner
    • Yandex Cloud Functions trigger
    • Backups
    • Quotas and limits
  • Access management
  • Pricing policy
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • ImageService
      • LifecyclePolicyService
      • RegistryService
      • RepositoryService
      • ScannerService
      • OperationService
    • REST
      • Overview
      • Image
        • Overview
        • delete
        • get
        • list
      • LifecyclePolicy
        • Overview
        • create
        • delete
        • dryRun
        • get
        • getDryRunResult
        • list
        • listDryRunResultAffectedImages
        • listDryRunResults
        • update
      • Registry
        • Overview
        • create
        • delete
        • get
        • list
        • listAccessBindings
        • listIpPermission
        • setAccessBindings
        • setIpPermission
        • update
        • updateAccessBindings
        • updateIpPermission
      • Repository
        • Overview
        • delete
        • get
        • getByName
        • list
        • listAccessBindings
        • setAccessBindings
        • updateAccessBindings
        • upsert
      • Scanner
        • Overview
        • get
        • getLast
        • list
        • listVulnerabilities
        • scan
  • Troubleshooting
  • Questions and answers
  1. Step-by-step instructions
  2. Managing Docker image lifecycle policies
  3. Updating a lifecycle policy

Updating a lifecycle policy

Written by
Yandex Cloud
  • 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.

To access the policy, use its ID. For information about getting a policy ID, see Getting information about lifecycle policies.

CLI
API

If you don't have the Yandex Cloud 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 crp6lg1868p3i0emkv1b --new-name new-policy
    

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.

Warning

You can only set a lifecycle policy for a repository. The policy applies to Docker images whose names match the repository name exactly. There is no support for prefix matching. You can't set a policy for a repository group, registry, folder, or cloud.

Examples

Updating 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. A test.* regular expression for tag_regexp lets you get 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. Parameter format: Number and unit of measurement 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 status

Activate 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 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 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.

{% include [name-format](../../../_includes/name-format.md) %}

Result:

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

Updating 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 is the new policy description.

Result:

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

Was the article helpful?

Language / Region
© 2022 Yandex.Cloud LLC
In this article:
  • Examples
  • Updating lifecycle policy rules
  • Updating a lifecycle policy status
  • Updating a lifecycle policy name
  • Updating a lifecycle policy description