Skip to content

Configure ACR retention policies#

Cost Optimization · Container Registry · Azure.ACR.Retention

Use a retention policy to cleanup untagged manifests.

Description#

Retention policy is a configurable option of Premium Azure Container Registry (ACR). When a retention policy is configured, untagged manifests in the registry are automatically deleted. A manifest is untagged when a more recent image is pushed using the same tag. i.e. latest.

The retention policy (in days) can be set to 0-365. The default is 7 days.

Recommendation#

Consider enabling a retention policy for untagged manifests.

Examples#

Configure with Azure template#

To deploy Container Registries that pass this rule:

  • Set properties.retentionPolicy.status to enabled.

For example:

{
    "type": "Microsoft.ContainerRegistry/registries",
    "apiVersion": "2021-06-01-preview",
    "name": "[parameters('registryName')]",
    "location": "[parameters('location')]",
    "sku": {
        "name": "Premium"
    },
    "identity": {
        "type": "SystemAssigned"
    },
    "properties": {
        "adminUserEnabled": false,
        "policies": {
            "quarantinePolicy": {
                "status": "enabled"
            },
            "trustPolicy": {
                "status": "enabled",
                "type": "Notary"
            },
            "retentionPolicy": {
                "status": "enabled",
                "days": 30
            }
        }
    }
}

Configure with Bicep#

To deploy Container Registries that pass this rule:

  • Set properties.retentionPolicy.status to enabled.

For example:

resource acr 'Microsoft.ContainerRegistry/registries@2021-06-01-preview' = {
  name: registryName
  location: location
  sku: {
    name: 'Premium'
  }
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    adminUserEnabled: false
    policies: {
      quarantinePolicy: {
        status: 'enabled'
      }
      trustPolicy: {
        status: 'enabled'
        type: 'Notary'
      }
      retentionPolicy: {
        status: 'enabled'
        days: 30
      }
    }
  }
}

Notes#

Retention policies for Azure Container Registry is currently in preview.


Last update: 2022-01-19