Reputation: 3583
I am trying to write a script to clean up the Azure container registry. The commands I used for this purpose are:
# Remove images with unwanted tags
az acr repository delete --name $registryName --image $imageName --yes
# Remove dangling images
az acr repository show-manifests --name $AzureRegistryName --repository $RepositoryName --query "[?tags[0]==null].digest" -o tsv `
| %{ az acr repository delete --name $AzureRegistryName --image $RepositoryName@$_ --yes }
imagename
refers to a combination of repository:unwantedtag
.
As specified above, I am using az acr repository delete
command. This deletes the manifest referenced by imagename
and all other tags referencing the same manifest.
If I have the same image with two different tags, namely test:100
and test:101
, then both will have same manifest. For cleanup purpose, I want to keep only one of them. If i delete one image test:100
, then removing the manifest will delete test:101
also. This is not desirable.
The other thing is if I want to delete both the tags during the cleanup, after deleting test:100
first, when I attempt to delete test:101
, it will return an error:
az : ERROR: Error: manifest unknown.
Even if it will not stop the script from executing further, the error is annoying. Both the tags are removed also.
So basically, what I need is a solution for this problem.
Will using az acr repository untag
command instead of delete
resolve this issue? What if I untag the images with unwanted tags and then run a command to remove dangling manifests?
How the delete
and untag
commands differ in this perspective?
Upvotes: 3
Views: 2485
Reputation: 3583
az acr repository delete
command deletes an image by tag. All layers unique to the image, and any other tags associated with the image are deleted.
az acr repository untag
command deletes the tag. No space is freed when you untag an image because its manifest and layer data remain in the registry. Only the tag reference itself is deleted.
The actual method I needed was first untagging the images and then remove the dangling manifests.
Upvotes: 3