|
| 1 | +--- |
| 2 | +title: Policy to retain untagged manifests in Azure Container Registry |
| 3 | +description: Learn how to enable a retention policy in your Azure container registry, for automatic deletion of untagged manifests after a defined period. |
| 4 | +services: container-registry |
| 5 | +author: dlepow |
| 6 | +manager: gwallace |
| 7 | + |
| 8 | +ms.service: container-registry |
| 9 | +ms.topic: article |
| 10 | +ms.date: 09/25/2019 |
| 11 | +ms.author: danlep |
| 12 | +--- |
| 13 | + |
| 14 | +# Set a retention policy for untagged manifests |
| 15 | + |
| 16 | +Azure Container Registry gives you the option to set a *retention policy* for stored image manifests that don't have any associated tags (*untagged manifests*). When a retention policy is enabled, untagged manifests in the registry are automatically deleted after a number of days you set. This feature prevents the registry from filling up with artifacts that aren't needed and helps you save on storage costs. If the `delete-enabled` attribute of an untagged manifest is set to `false`, the manifest can't be deleted, and the retention policy doesn't apply. |
| 17 | + |
| 18 | +You can use the Azure Cloud Shell or a local installation of the Azure CLI to run the command examples in this article. If you'd like to use it locally, version 2.0.74 or later is required. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][azure-cli]. |
| 19 | + |
| 20 | +> [!IMPORTANT] |
| 21 | +> This feature is currently in preview, and some [limitations apply](#preview-limitations). Previews are made available to you on the condition that you agree to the [supplemental terms of use][terms-of-use]. Some aspects of this feature may change prior to general availability (GA). |
| 22 | +
|
| 23 | +> [!WARNING] |
| 24 | +> Set a retention policy with care--deleted image data is UNRECOVERABLE. If you have systems that pull images by manifest digest (as opposed to image name), you should not set a retention policy for untagged manifests. Deleting untagged images will prevent those systems from pulling the images from your registry. Instead of pulling by manifest, consider adopting a *unique tagging* scheme, a [recommended best practice](container-registry-image-tag-version.md). |
| 25 | +
|
| 26 | +If you want to delete single image tags or manifests using Azure CLI commands, see [Delete container images in Azure Container Registry](container-registry-delete.md). |
| 27 | + |
| 28 | +## Preview limitations |
| 29 | + |
| 30 | +* Only a **Premium** container registry can be configured with a retention policy. For information about registry service tiers, see [Azure Container Registry SKUs](container-registry-skus.md). |
| 31 | +* You can only set a retention policy for untagged manifests. |
| 32 | + |
| 33 | +## Set a retention policy - CLI |
| 34 | + |
| 35 | +The following example shows you how to use the Azure CLI to set a retention policy for untagged manifests in a registry. |
| 36 | + |
| 37 | +### Enable a retention policy |
| 38 | + |
| 39 | +By default, no retention policy is set in a container registry. To set or update a retention policy, run the [az acr config retention update][az-acr-config-retention-update] command in the Azure CLI. You can specify a number of days between 0 and 365 to retain the untagged manifests. If you don't specify a number of days, the command sets a default of 7 days. After the retention period, all untagged manifests in the registry are automatically deleted. |
| 40 | + |
| 41 | +The following example sets a retention policy of 30 days for untagged manifests in the registry *myregistry*: |
| 42 | + |
| 43 | +```azurecli |
| 44 | +az acr config retention update --name myregistry --status enabled --days 30 --type UntaggedManifests |
| 45 | +``` |
| 46 | + |
| 47 | +The following example sets a policy to delete any manifest in the registry as soon as it's untagged. Create this policy by setting a retention period of 0 days: |
| 48 | + |
| 49 | +```azurecli |
| 50 | +az acr config retention update --name myregistry --status enabled --days 0 --type UntaggedManifests |
| 51 | +``` |
| 52 | + |
| 53 | +### Disable a retention policy |
| 54 | + |
| 55 | +To see the retention policy set in a registry, run the [az acr config retention show][az-acr-config-retention-show] command: |
| 56 | + |
| 57 | +```azurecli |
| 58 | +az acr config retention show --name myregistry |
| 59 | +``` |
| 60 | + |
| 61 | +To disable a retention policy in a registry, run the [az acr config retention update][az-acr-config-retention-update] command and set `--status disabled`: |
| 62 | + |
| 63 | +```azurecli |
| 64 | +az acr config retention update --name myregistry --status disabled |
| 65 | +``` |
| 66 | + |
| 67 | +## Set a retention policy - portal |
| 68 | + |
| 69 | +You can also set a registry's retention policy in the [Azure portal](https://portal.azure.com). The following example shows you how to use the portal to set a retention policy for untagged manifests in a registry. |
| 70 | + |
| 71 | +### Enable a retention policy |
| 72 | + |
| 73 | +1. Navigate to your Azure container registry. Under **Policies**, select **Retention** (Preview). |
| 74 | +1. In **Status**, select **Enabled**. |
| 75 | +1. Select a number of days between 0 and 365 to retain the untagged manifests. Select **Save**. |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +### Disable a retention policy |
| 80 | + |
| 81 | +1. Navigate to your Azure container registry. Under **Policies**, select **Retention** (Preview). |
| 82 | +1. In **Status**, select **Disabled**. Select **Save**. |
| 83 | + |
| 84 | +## Next steps |
| 85 | + |
| 86 | +* Learn more about options to [delete images and repositories](container-registry-delete.md) in Azure Container Registry |
| 87 | + |
| 88 | +* Learn how to [automatically purge](container-registry-auto-purge.md) selected images and manifests from a registry |
| 89 | + |
| 90 | +* Learn more about options to [lock images and manifests](container-registry-image-lock.md) in a registry |
| 91 | + |
| 92 | +<!-- LINKS - external --> |
| 93 | +[terms-of-use]: https://azure.microsoft.com/support/legal/preview-supplemental-terms/ |
| 94 | + |
| 95 | + |
| 96 | +<!-- LINKS - internal --> |
| 97 | +[azure-cli]: /cli/azure/install-azure-cli |
| 98 | +[az-acr-config-retention-update]: /cli/azure/acr/config/retention#az-acr-config-retention-update |
| 99 | +[az-acr-config-retention-show]: /cli/azure/acr/config/retention#az-acr-config-retention-show |
0 commit comments