Creating a lifecycle policy
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id options.
-
Prepare lifecycle policy rules and save them to a file named
rules.json.Here is an example of a
rules.jsonfile containing a soft delete rule for Docker images with tags more than 30 days old, with a 10-day waiting period:[ { "path_prefix": "ubuntu.*", "delete": { "type": "SOFT_DELETE", "cooldown_period_days": 10, "older_than_days": 30 }, "docker_filters": { "tag_status": "TAGGED" } } ] -
Create a lifecycle policy:
yc cloud-registry registry lifecycle-policy create \ --name <policy_name> \ --description <policy_description> \ --registry-id <registry_ID> \ --state <policy_state> \ --rules <path_to_rules.json>Where:
-
--name: Policy name. -
--description: Policy description. This is an optional parameter. -
--registry-id: ID of the registry for which you are creating the policy. There are quotas and limits on the number of lifecycle policies per registry. -
--state: Policy state after creation:DISABLEDorENABLED.Note
To avoid errors, we recommend creating a policy in
DISABLEDstate and enabling it after checking the rules. -
--rules: Path to the policy rule file in JSON format.
Result:
done (1s) id: e5oq6cd3fuue******** name: my-lifecycle-policy description: My lifecycle policy rules: - path_prefix: ubuntu.* delete: type: SOFT_DELETE cooldown_period_days: "10" older_than_days: "30" docker_filters: tag_status: TAGGED state: DISABLED registry_id: e5o6a2blpkb6******** created_at: "2026-01-21T14:47:01.061840Z" modified_at: "2026-01-21T14:47:01.061840Z" created_by: bfb7vsfljr3j******** modified_by: bfb7vsfljr3******** -
To create a lifecycle policy, use the Create REST API method for the LifecyclePolicy resource or the LifecyclePolicyService/Create gRPC API call.