14

有没有办法只删除特定标签?我只找到了一种使用REST / cli-acr删除整个注册表的方法

谢谢

4

9 回答 9

9

从下面复制的更新:

作为更新,今天我们发布了一些功能的预览,包括存储库删除、个人 Azure Active Directory 登录和 Webhook。

原答案:

我们将在本月晚些时候为我们的 GA 版本加强注册表。我们推迟了所有新功能,同时专注于性能、可靠性和其他 Azure 数据中心,通过 GA 在所有公共数据中心提供 ACR。我们将在未来的版本中提供删除图像和标签的功能。我们开始使用https://github.com/Azure/acr/来跟踪功能和错误。此处捕获删除:https ://github.com/Azure/acr/issues/33

感谢您的反馈,史蒂夫

于 2017-03-18T19:42:54.690 回答
9

这是一个删除所有 Azure 容器注册表标签的 powershell 脚本,标签 MyTag1 和 MyTag2 除外:

az acr repository show-tags -n MyRegistry --repository MyRepository | ConvertFrom-String | %{$_.P2 -replace "[`",]",""} | where {$_ -notin "MyTag1","MyTag2"  } | % {az acr repository delete -n MyRegistry --repository MyRepository --tag $_ --yes}

它使用Azure CLI 2.0

于 2018-02-07T09:37:10.857 回答
8

您可以使用Azure CLI 2.0从具有给定标记的存储库中删除图像:

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

  • MyRegistry是您的 Azure 容器注册表的名称
  • MyRepository是存储库的名称
  • MyTag表示要删除的标签。

您还可以选择通过省略删除整个存储库--tag MyTagaz acr repository delete可以在此处找到有关该命令的更多信息: https ://docs.microsoft.com/en-us/cli/azure/acr/repository#delete

于 2017-08-17T13:48:51.603 回答
4

我有一个类似的问题,我想从存储库中删除历史图像,因为我们的配额已达到 100%

我可以通过在 Azure CLI 2.0 中使用以下命令来做到这一点。该过程执行以下操作:获取标签列表,使用 grep 过滤并使用 sed 清理,然后将其传递给删除命令。

获取给定存储库的所有标签

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

获取以特定输入开头的所有标签并将其传递给 sed ,这将删除尾随逗号

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

使用 xargs,将输出分配给变量 X 并将其用作标记。

--manifest :删除标签引用的清单。这也会删除任何关联的层数据和引用清单的所有其他标签。

--yes -y :不提示确认。

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

例如,registry = myRegistry,repository = myRepo,我想删除所有以标记名“test”开头的标记(这将包括 test123、testing 等)

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

可以在此处找到更多信息Microsoft Azure Docs

于 2017-10-24T22:15:18.763 回答
2

以下来自@christianliebel Azure CLI的回答会生成错误unrecognized arguments: --tag MyTag

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

我正在使用:

➜ az --version
azure-cli                         2.11.1

这有效:

➜ 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 文档示例:

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

于 2020-09-10T13:02:25.680 回答
1

作为更新,今天我们发布了一些功能的预览,包括存储库删除、个人 Azure Active Directory 登录和 Webhook。史蒂夫

于 2017-07-06T20:00:19.917 回答
0

我尝试了所有命令,但没有一个起作用。虽然它可以堆叠,所以我去了我的门户 azure 并自己删除了我的存储库。有用

于 2019-09-18T16:01:59.720 回答
0

以下命令有助于删除遵循名称或搜索模式的特定图像:-

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'

我的用例是删除在 2020 年 8 月之前创建的所有容器注册表,因此我复制了以下命令的输出然后执行它们,因为我的清单名称的创建日期如下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'

参考:Microsoft ACR CLI

于 2020-08-11T12:10:09.070 回答
0

我已使用 REST Api 从特定存储库中删除空标记图像,此处提供文档

import os
import sys
import yaml
import json
import requests

config = yaml.safe_load(
    open(os.path.join(sys.path[0], "acr-config.yml"), 'r'))
"""
Sample yaml file
acr_url: "https://youregistryname.azurecr.io"
acr_user_name: "acr_user_name_from_portal"
acr_password: "acr_password_from_azure_portal"
# Remove the repo name so that it will clean all the repos
repo_to_cleanup: some_repo
"""
acr_url = config.get('acr_url')
acr_user_name = config.get("acr_user_name")
acr_password = config.get("acr_password")
repo_to_cleanup = config.get("repo_to_cleanup")


def iterate_images(repo1, manifests):
    for manifest in manifests:
        try:
            tag = manifest['tags'][0] if 'tags' in manifest.keys() else ''
            digest = manifest['digest']
            if tag is None or tag == '':
                delete = requests.delete(f"{acr_url}/v2/{repo1}/manifests/{digest}", auth=(acr_user_name, acr_password))
                print(f"deleted the Tag = {tag} , Digest= {digest}, Status {str(delete)} from Repo {repo1}")
        except Exception as ex:
            print(ex)


if __name__ == '__main__':
    result = requests.get(f"{acr_url}/acr/v1/_catalog", auth=(acr_user_name, acr_password))
    repositories = json.loads(result.content)
    for repo in repositories['repositories']:
        if repo_to_cleanup is None or repo == repo_to_cleanup:
            manifests_binary = requests.get(f"{acr_url}/acr/v1/{repo}/_manifests", auth=(acr_user_name, acr_password))
            manifests_json = json.loads(manifests_binary.content)
            iterate_images(repo, manifests_json['manifests'])
于 2021-10-15T11:17:29.167 回答