Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Artifact cache provides pull-through caching (PTC) for images from upstream registries. By default, you can't push artifacts directly to repositories targeted by cache rules.
Enable writable cache repositories to push your own images and OCI artifacts to these repositories. For example, you can publish a patched image under a new tag or attach supply chain artifacts, such as signatures and lifecycle metadata, to an image in a cache-backed repository.
You can also prehydrate the cache by pushing or importing images into a cache-backed repository before workloads request them. Prehydrating makes those images available locally for subsequent pulls, avoiding the initial upstream fetch on the workload's first pull.
The setting applies to the registry, not to an individual cache rule. You don't need to recreate existing cache rules.
Important
Writable cache repositories are in preview. Enabling this setting permits authorized clients to write to repositories targeted by cache rules throughout the registry. Review repository permissions before enabling it.
Prerequisites
- An Azure container registry with an artifact cache rule. Artifact cache is available in the Basic, Standard, and Premium service tiers.
- Azure CLI version 2.89.0 or later. Run
az versionto check your version. See Install Azure CLI if you need to install or update it. - Permission to update the registry configuration, such as the Container Registry Contributor and Data Access Configuration Administrator role.
- Permission to push and pull artifacts in the target repository. For registries using RBAC Registry + ABAC Repository Permissions, use Container Registry Repository Writer, with repository conditions where appropriate. For registries using RBAC Registry Permissions, use AcrPush. See Azure Container Registry roles and permissions.
- Docker installed and running if you follow the push example.
Enabling writable repositories doesn't grant data-plane permissions or change the credentials used to access the upstream registry.
The following examples use Bash, which is available in Azure Cloud Shell. Run the Docker commands in an environment with a running Docker daemon.
Enable writable cache repositories
Sign in and select the subscription containing your registry:
az login
az account set --subscription "<subscription-id>"
Set the registry name and resource group:
registryName="<registry-name>"
resourceGroup="<resource-group-name>"
Enable writes to cache-backed repositories:
az acr update --name "$registryName" --resource-group "$resourceGroup" --writable-cache-repos Enabled
Verify the setting:
az acr show --name "$registryName" --resource-group "$resourceGroup" --query writableCacheRepos --output tsv
The expected output is:
Enabled
To enable the setting when creating a registry, include the same parameter in az acr create. The resource group must already exist, and the registry name must be globally unique:
az acr create --name "$registryName" --resource-group "$resourceGroup" --sku Standard --writable-cache-repos Enabled
Creating a registry with this setting doesn't create cache rules. Configure a rule before using pull-through caching.
Push an image to a cache-backed repository
This example uses an existing cache rule that maps mcr.microsoft.com/hello-world to the target repository cache/hello-world. If you don't have this rule, create it by using an unused target repository path. Creating a rule also requires cache-rule management permissions, such as the Container Registry Cache Rule Administrator role:
az acr cache create --registry "$registryName" --resource-group "$resourceGroup" --name hello-world-cache --source-repo mcr.microsoft.com/hello-world --target-repo cache/hello-world
If you're using a different existing rule, substitute its target repository and an available upstream tag in the following commands.
Get the registry's login server and authenticate Docker:
loginServer=$(az acr show --name "$registryName" --resource-group "$resourceGroup" --query loginServer --output tsv)
az acr login --name "$registryName"
Pull an upstream image through the cache rule:
docker pull "$loginServer/cache/hello-world:latest"
Push the image back to the same repository under a distinct tag:
docker tag "$loginServer/cache/hello-world:latest" "$loginServer/cache/hello-world:local-demo-v1"
docker push "$loginServer/cache/hello-world:local-demo-v1"
This example retags the image to demonstrate a write operation; it doesn't modify or patch the image. In a patching workflow, build and test your modified image, then push it under a distinct tag.
Verify that you can pull the new tag:
docker image rm "$loginServer/cache/hello-world:local-demo-v1"
docker pull "$loginServer/cache/hello-world:local-demo-v1"
The new tag is stored in your ACR repository. It isn't pushed to the upstream registry.
Attach lifecycle metadata to a cached image
Writable cache repositories also let you attach OCI artifacts to a cached image without write access to the upstream registry. For example, you can attach end-of-life (EOL) metadata to the image cached from Microsoft Artifact Registry in the preceding example.
Install the ORAS CLI, and then authenticate it with your Azure CLI identity:
az acr login --name "$registryName" --expose-token --query accessToken --output tsv | oras login "$loginServer" --username 00000000-0000-0000-0000-000000000000 --password-stdin
Attach an OCI artifact containing an example EOL date:
oras attach --artifact-type application/vnd.microsoft.artifact.lifecycle --annotation "vnd.microsoft.artifact.lifecycle.end-of-life.date=2027-12-31" "$loginServer/cache/hello-world:latest"
Discover the artifacts attached to the image:
oras discover "$loginServer/cache/hello-world:latest"
The lifecycle artifact is stored in your downstream ACR repository and refers to the image digest resolved from the tag. It doesn't modify the upstream image or publish metadata to Microsoft Artifact Registry. If the tag later resolves to a different image digest, the lifecycle artifact still refers to the original digest.
The EOL annotation is metadata; it doesn't automatically expire the image or prevent pulls. To enforce a lifecycle policy, use tooling that reads and acts on the metadata.
Behavior and considerations
- Registry-wide setting: Writable cache repositories are disabled by default. When you enable the setting, it applies to repositories targeted by existing and future cache rules in the registry.
- Authorization still applies: Clients need the usual permissions to push images or OCI artifacts. Repository locks and other write restrictions aren't bypassed.
- Use distinct tags: Use a separate naming convention for locally published images, such as
local-demo-v1or a build-specific patched tag. Avoid reusing tags supplied by the upstream repository. - No upstream write-back: Local pushes don't modify the upstream registry. Upstream authentication requirements remain unchanged.
- Pull-through caching continues: Enabling writes doesn't proactively download every upstream image or introduce automatic synchronization of new tags.
- Local-only content needs its own recovery strategy: Content that exists only in your registry can't be recovered from the upstream registry if you delete it.
- Discovery is separate: Enabling writes doesn't by itself provide a merged inventory of upstream and locally stored repositories or tags.
Tag resolution and upstream refresh
A locally pushed or imported tag isn't a permanent override of an upstream tag. When PTC rechecks upstream, it compares the current upstream digest with the last upstream digest it synchronized.
Suppose the downstream tag app:v1 points to digest A, while upstream points to B:
| Sync history | Result when PTC rechecks upstream |
|---|---|
| The tag has never been synchronized from upstream. | PTC returns B and queues an import that can overwrite the downstream tag with B. |
| PTC previously synchronized B, then you replaced the downstream tag with A. Upstream still contains B. | PTC preserves A, provided the recorded last-synchronized digest is B. |
| Same history, but upstream changes from B to C. | PTC returns C and queues a refresh that can replace the local override with C. |
Between upstream rechecks, pulls can use the current downstream tag. Resolution isn't determined simply by which registry received the latest push.
Important
Use distinct tags for locally published images to avoid collisions with upstream tags. Pull by digest when you require a specific image version.
Disable writable cache repositories
To stop allowing direct writes to cache-backed repositories, disable the setting:
az acr update --name "$registryName" --resource-group "$resourceGroup" --writable-cache-repos Disabled
Verify the setting:
az acr show --name "$registryName" --resource-group "$resourceGroup" --query writableCacheRepos --output tsv
The expected output is Disabled. This operation changes the write setting; it isn't a content cleanup operation.
Troubleshoot
| Symptom | Action |
|---|---|
Azure CLI doesn't recognize --writable-cache-repos. |
Check az version and update to Azure CLI 2.89.0 or later. The parameter name ends in repos, not repo. |
| A push reports that pushes to a repository matching a cache rule aren't supported. | Verify that az acr show --query writableCacheRepos returns Enabled for the destination registry. |
| A push returns an authorization error. | Check the client's repository write permissions and the registry's role assignment permissions mode. Enabling this setting doesn't assign roles. |
| A cache-rule creation attempt fails because the target already exists or overlaps another rule. | Use an unused, nonoverlapping target path, or use the existing rule. You don't need a new rule to enable writes. |
| Pulling an upstream image fails after writes are enabled. | Check upstream credentials, source availability, network access, and the cache-rule configuration. Writable repositories don't change these requirements. |