问题
I want to delete all images in Azure Container Registry except the last two. I was looking for an script for do so but I only find to delete images older than X days. This is not possible for my situation because some days there are a lot of images created and other days only one.
Somebody has any idea?
回答1:
I am unable to test it right now but this little PowerShell script should work:
$acrName = 'YourACRName'
$repo = az acr repository list --name $acrName
$repo | Convertfrom-json | Foreach-Object {
$imageName = $_
(az acr repository show-tags -n $acrName --repository $_ |
convertfrom-json |) Select-Object -SkipLast 2 | Foreach-Object {
az acr repository delete -n $acrName --image "$imageName:$_"
}
}
It retrieves all tags for each repository, skips the last 2, then it iterates over each tag and deletes it.
Please test it in some kind of test environment first.
来源:https://stackoverflow.com/questions/57579940/azure-container-registry-delete-all-images-except-2