How to delete image from Azure Container Registry

后端 未结 8 936
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 09:13

Is there a way to delete specific tags only? I only found a way to delete the whole registry using the REST/cli-acr

Thanks

相关标签:
8条回答
  • 2020-12-29 09:25

    I tried all commands but none worked.I though that it could be stacked so I went to my portal azure and deleted my repository by myself. It works

    0 讨论(0)
  • 2020-12-29 09:31

    Following command helps while deleting specific images following a name or search pattern :-

    az acr repository show-manifests -n myRegistryName --repository myRepositoryName --query '[].tags[0]' -o yaml | grep 'mySearchPattern' | sed 's/- /az acr repository delete --name myRegistryName --yes --image myRepositoryName:/g'
    

    My use case was to delete all Container Registeries which were created before August in 2020 so I copied the output of the following command and then executed them, as my manifest names had creation Date like DDMMYYYY-HHMM:-

    az acr repository show-manifests -n myRegistryName --repository myRepositoryName --query '[].tags[0]' -o yaml | grep '[0-7]2020-' | sed 's/- /az acr repository delete --name myRegistryName --yes --image myRepositoryName:/g'
    

    Reference: Microsoft ACR CLI

    0 讨论(0)
  • 2020-12-29 09:31

    Following answer from @christianliebel Azure CLI generates error unrecognized arguments: --tag MyTag:

    ➜ az acr repository delete -n MyRegistry --repository MyRepository --tag MyTag
    az: error: unrecognized arguments: --tag MyTag
    

    I was using:

    ➜ az --version
    azure-cli                         2.11.1
    

    This works:

    ➜ az acr repository delete --name MyRegistry --image Myrepository:Mytag
    This operation will delete the manifest 'sha256:c88ac1f98fce390f5ae6c56b1d749721d9a51a5eb4396fbc25f11561817ed1b8' and all the following images: 'Myrepository:Mytag'.
    Are you sure you want to continue? (y/n): y
    ➜
    

    Microsoft Azure CLI docs example:

    https://docs.microsoft.com/en-us/cli/azure/acr/repository?view=azure-cli-latest#az-acr-repository-delete-examples

    0 讨论(0)
  • 2020-12-29 09:32

    You can use Azure CLI 2.0 to delete images from a repository with a given tag:

    az acr repository delete -n MyRegistry --repository MyRepository --tag MyTag

    • MyRegistry is the name of your Azure Container Registry
    • MyRepository is the name of the repository
    • MyTag denotes the tag you want to delete.

    You can also choose to delete the whole repository by omitting --tag MyTag. More information about the az acr repository delete command can be found here: https://docs.microsoft.com/en-us/cli/azure/acr/repository#delete

    0 讨论(0)
  • 2020-12-29 09:32

    I had a similar problem where I wanted to remove historical images from the repository as our quota had reached 100%

    I was able to do this by using the following commands in the Azure CLI 2.0. The process does the following : obtain a list of tags, filter it with grep and clean it up with sed before passing it to the delete command.

    Get all the tags for the given repository

    az acr repository show-tags -n [registry] --repository [repository] 
    

    Get all the tags that start with the specific input and pipe that to sed which will remove the trailing comma

    grep \"[starts with] | sed 's/,*$//g'
    

    Using xargs, assign the output to the variable X and use that as the tag.

    --manifest : Delete the manifest referenced by a tag. This also deletes any associated layer data and all other tags referencing the manifest.

    --yes -y : Do not prompt for confirmation.

    xargs -I X az acr repository delete -n [registry] --repository [repository] --tag X --manifest --yes
    

    e.g. registry = myRegistry, repository = myRepo, I want to remove all tags that start with the tagname 'test' ( this would include test123, testing etc )

    az acr repository show-tags -n myRegistry --repository myRepo | grep \"test | sed 's/,*$//g' | xargs -I X az acr repository delete -n myRegistry --repository myRepo --tag X --manifest --yes
    

    More information can be found here Microsoft Azure Docs

    0 讨论(0)
  • 2020-12-29 09:35

    As an update, today we've released a preview of several features including repository delete, Individual Azure Active Directory Logins and Webhooks. Steve

    0 讨论(0)
提交回复
热议问题