Creating a lifecycle policy
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
-
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 setting. -
--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.