Skip to content

Commit a813428

Browse files
committed
clarify delete operation, remove CLI script for untagged manifests
1 parent 086b2cd commit a813428

File tree

2 files changed

+14
-80
lines changed

2 files changed

+14
-80
lines changed

articles/container-registry/container-registry-auto-purge.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Purge tags and manifests
33
description: Use a purge command to delete multiple tags and manifests from an Azure container registry based on age and a tag filter, and optionally schedule purge operations.
44
ms.topic: article
5-
ms.date: 02/19/2021
5+
ms.date: 05/07/2021
66
---
77

88
# Automatically purge images from an Azure container registry
@@ -13,9 +13,6 @@ The `acr purge` command is currently distributed in a public container image (`m
1313

1414
You can use the Azure Cloud Shell or a local installation of the Azure CLI to run the ACR task examples in this article. If you'd like to use it locally, version 2.0.76 or later is required. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][azure-cli-install].
1515

16-
> [!IMPORTANT]
17-
> This feature is currently in preview. 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).
18-
1916
> [!WARNING]
2017
> Use the `acr purge` command with caution--deleted image data is UNRECOVERABLE. If you have systems that pull images by manifest digest (as opposed to image name), you should not purge untagged images. 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).
2118

articles/container-registry/container-registry-delete.md

Lines changed: 13 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
title: Delete image resources
33
description: Details on how to effectively manage registry size by deleting container image data using Azure CLI commands.
44
ms.topic: article
5-
ms.date: 07/31/2019
5+
ms.date: 05/07/2021
66
---
77

8-
# Delete container images in Azure Container Registry using the Azure CLI
8+
# Delete container images in Azure Container Registry
99

1010
To maintain the size of your Azure container registry, you should periodically delete stale image data. While some container images deployed into production may require longer-term storage, others can typically be deleted more quickly. For example, in an automated build and test scenario, your registry can quickly fill with images that might never be deployed, and can be purged shortly after completing the build and test pass.
1111

@@ -15,10 +15,11 @@ Because you can delete image data in several different ways, it's important to u
1515
* Delete by [tag](#delete-by-tag): Deletes an image, the tag, all unique layers referenced by the image, and all other tags associated with the image.
1616
* Delete by [manifest digest](#delete-by-manifest-digest): Deletes an image, all unique layers referenced by the image, and all tags associated with the image.
1717

18-
Sample scripts are provided to help automate delete operations.
19-
2018
For an introduction to these concepts, see [About registries, repositories, and images](container-registry-concepts.md).
2119

20+
> [!NOTE]
21+
> After you delete image data, Azure Container Registry stops billing you immediately for the associated storage. However, the registry recovers the associated storage space using an asynchronous process. It takes some time before the registry cleans up layers and shows the updated storage usage.
22+
2223
## Delete repository
2324

2425
Deleting a repository deletes all of the images in the repository, including all tags, unique layers, and manifests. When you delete a repository, you recover the storage space used by the images that reference unique layers in that repository.
@@ -102,7 +103,7 @@ The `acr-helloworld:v2` image is deleted from the registry, as is any layer data
102103

103104
To maintain the size of a repository or registry, you might need to periodically delete manifest digests older than a certain date.
104105

105-
The following Azure CLI command lists all manifest digest in a repository older than a specified timestamp, in ascending order. Replace `<acrName>` and `<repositoryName>` with values appropriate for your environment. The timestamp could be a full date-time expression or a date, as in this example.
106+
The following Azure CLI command lists all manifest digests in a repository older than a specified timestamp, in ascending order. Replace `<acrName>` and `<repositoryName>` with values appropriate for your environment. The timestamp could be a full date-time expression or a date, as in this example.
106107

107108
```azurecli
108109
az acr repository show-manifests --name <acrName> --repository <repositoryName> \
@@ -196,85 +197,21 @@ As mentioned in the [Manifest digest](container-registry-concepts.md#manifest-di
196197

197198
As you can see in the output of the last step in the sequence, there is now an orphaned manifest whose `"tags"` property is an empty list. This manifest still exists within the registry, along with any unique layer data that it references. **To delete such orphaned images and their layer data, you must delete by manifest digest**.
198199

199-
## Delete all untagged images
200-
201-
You can list all untagged images in your repository using the following Azure CLI command. Replace `<acrName>` and `<repositoryName>` with values appropriate for your environment.
202-
203-
```azurecli
204-
az acr repository show-manifests --name <acrName> --repository <repositoryName> --query "[?tags[0]==null].digest"
205-
```
206-
207-
Using this command in a script, you can delete all untagged images in a repository.
208-
209-
> [!WARNING]
210-
> Use the following sample scripts with caution--deleted image data is UNRECOVERABLE. If you have systems that pull images by manifest digest (as opposed to image name), you should not run these scripts. 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).
211-
212-
**Azure CLI in Bash**
213-
214-
The following Bash script deletes all untagged images from a repository. It requires the Azure CLI and **xargs**. By default, the script performs no deletion. Change the `ENABLE_DELETE` value to `true` to enable image deletion.
215-
216-
```bash
217-
#!/bin/bash
218-
219-
# WARNING! This script deletes data!
220-
# Run only if you do not have systems
221-
# that pull images via manifest digest.
222-
223-
# Change to 'true' to enable image delete
224-
ENABLE_DELETE=false
225-
226-
# Modify for your environment
227-
REGISTRY=myregistry
228-
REPOSITORY=myrepository
200+
## Automatically purge tags and manifests
229201

230-
# Delete all untagged (orphaned) images
231-
if [ "$ENABLE_DELETE" = true ]
232-
then
233-
az acr repository show-manifests --name $REGISTRY --repository $REPOSITORY --query "[?tags[0]==null].digest" -o tsv \
234-
| xargs -I% az acr repository delete --name $REGISTRY --image $REPOSITORY@% --yes
235-
else
236-
echo "No data deleted."
237-
echo "Set ENABLE_DELETE=true to enable image deletion of these images in $REPOSITORY:"
238-
az acr repository show-manifests --name $REGISTRY --repository $REPOSITORY --query "[?tags[0]==null]" -o tsv
239-
fi
240-
```
241-
242-
**Azure CLI in PowerShell**
243-
244-
The following PowerShell script deletes all untagged images from a repository. It requires PowerShell and the Azure CLI. By default, the script performs no deletion. Change the `$enableDelete` value to `$TRUE` to enable image deletion.
245-
246-
```powershell
247-
# WARNING! This script deletes data!
248-
# Run only if you do not have systems
249-
# that pull images via manifest digest.
250-
251-
# Change to '$TRUE' to enable image delete
252-
$enableDelete = $FALSE
253-
254-
# Modify for your environment
255-
$registry = "myregistry"
256-
$repository = "myrepository"
257-
258-
if ($enableDelete) {
259-
az acr repository show-manifests --name $registry --repository $repository --query "[?tags[0]==null].digest" -o tsv `
260-
| %{ az acr repository delete --name $registry --image $repository@$_ --yes }
261-
} else {
262-
Write-Host "No data deleted."
263-
Write-Host "Set `$enableDelete = `$TRUE to enable image deletion."
264-
az acr repository show-manifests --name $registry --repository $repository --query "[?tags[0]==null]" -o tsv
265-
}
266-
```
202+
Azure Container Registry provides the following automated methods to remove tags and manifests, and their associated unique layer data:
267203

204+
* Create an ACR task that runs the `acr purge` container command to delete all tags that are older than a certain duration or match a specified name filter. Optionally configure `acr purge` to delete untagged manifests.
268205

269-
## Automatically purge tags and manifests (preview)
206+
For more information, see [Automatically purge images from an Azure container registry](container-registry-auto-purge.md).
270207

271-
As an alternative to scripting Azure CLI commands, run an on-demand or scheduled ACR task to delete all tags that are older than a certain duration or match a specified name filter. For more information, see [Automatically purge images from an Azure container registry](container-registry-auto-purge.md).
208+
* Optionally set a [retention policy](container-registry-retention-policy.md) for each registry, to manage untagged manifests. When you enable a retention policy, image manifests in the registry that don't have any associated tags, and the underlying layer data, are automatically deleted after a set period.
272209

273-
Optionally set a [retention policy](container-registry-retention-policy.md) for each registry, to manage untagged manifests. When you enable a retention policy, image manifests in the registry that don't have any associated tags, and the underlying layer data, are automatically deleted after a set period.
210+
The retention policy is currently a preview feature of **Premium** container registries. The retention policy applies to untagged manifests created after the policy takes effect.
274211

275212
## Next steps
276213

277-
For more information about image storage in Azure Container Registry see [Container image storage in Azure Container Registry](container-registry-storage.md).
214+
For more information about image storage in Azure Container Registry, see [Container image storage in Azure Container Registry](container-registry-storage.md).
278215

279216
<!-- IMAGES -->
280217
[manifest-digest]: ./media/container-registry-delete/01-manifest-digest.png

0 commit comments

Comments
 (0)