5

I am storing my docker images in a private repository on Azure. Everytime I push an image to that repository with the same tag (e.g., latest), the previous image becomes untagged, but remains in the repository. This has led to stacking a lot of untagged images, in the repository. I would like a command, using the azure cli, to delete all the untagged images in just one go.

For instance, typing the following command:

az acr repository show-manifests -n myRegistry --repository myRepo

returned several manifests for the d24-staging-fuzzy-search-srv repository:

[ { "digest": "sha256:blablabla1", "tags": null, "timestamp": "t1" }, { "digest": "sha256:blablabla2", "tags": null, "timestamp": "t2" }, { "digest": "sha256:blablabla3", "tags": [ "latest" ], "timestamp": "t3" }]

I would like to have a command in azure cli that deletes all the mainfests that have a tag of "null" and keep the one that has the tag "latest"

Nicolas El Khoury
  • 5,867
  • 4
  • 18
  • 28

4 Answers4

2

In case someone is still wondering what is the one liner command to accomplish this, please use the following Bash Script:

az acr repository show-manifests -n <registryName> --repository <repositoryName> --query "[?tags[0]==null].digest" -o tsv | xargs -I% az acr repository delete -n <registryName> -t <repositoryName>@% -y

Source: https://learn.microsoft.com/en-us/azure/container-registry/container-registry-faq

Header: How do I delete all manifests that are not referenced by any tag in a repository?

  • This removes too many manifests when using buildx: only the platform-agnostic-manifest has a tag. This command removes the actual image and leaves the tag unusable. – Erik van Velzen Aug 14 '23 at 13:07
2

For Linux bash

az acr repository show-manifests -n myRegistry --repository myRepository --query "[?tags[0]==null].digest" -o tsv | xargs -I% az acr repository delete -n myRegistry -t myRepository@% --yes

For Windows PowerShell:

az acr repository show-manifests -n myRegistry --repository myRepository --query "[?tags[0]==null].digest" -o tsv | %{ az acr repository delete -n myRegistry -t myRepository@$_ --yes }

rafalkasa
  • 1,743
  • 20
  • 20
  • The `repository show-manifests` command is apparently being deprecated. I found this to work as a replacement: `az acr manifest list-metadata -r myRegistry -n myRepository --query "[?tags[0]==null].digest" -o tsv | xargs -I% az acr repository delete -n myRegistry -t myRepository% --yes` – Chris L8 Jun 16 '23 at 19:04
1

Try to use the command below.

az acr repository delete -n yourRegistry --image yourRepo:null

For more details, refer to this article.

Delete an image by tag. This deletes the manifest referenced by 'hello-world:latest', all other tags referencing the manifest, and any associated layer data.

az acr repository delete -n MyRegistry --image hello-world:latest

Community
  • 1
  • 1
Joy Wang
  • 39,905
  • 3
  • 30
  • 54
-1

I ended up creating a node script, in which I injected azure cli commands using shelljs.

Basically what I did is, For each repository, I fetched all its manifests, and for each manifests that does not contain the label "latest" was deleted

Nicolas El Khoury
  • 5,867
  • 4
  • 18
  • 28