![](/img/trans.png)
[英]How to pull container image from docker registry to deploy azure container
[英]How to delete image from Azure Container Registry
从下面复制的更新:
作为更新,今天我们发布了多项功能的预览版,包括存储库删除、个人 Azure Active Directory 登录和 Webhook。
原答案:
我们正在为本月晚些时候的 GA 版本强化注册表。 我们推迟了所有新功能,同时专注于性能、可靠性和额外的 Azure 数据中心,通过 GA 在所有公共数据中心提供 ACR。 我们将在未来的版本中提供删除图像和标签的功能。 我们开始使用https://github.com/Azure/acr/来跟踪功能和错误。 删除在此处捕获: https : //github.com/Azure/acr/issues/33
感谢您的反馈,史蒂夫
可以使用Azure CLI 2.0从具有给定标记的存储库中删除图像:
az acr repository delete -n MyRegistry --repository MyRepository --tag MyTag
MyRegistry
是 Azure 容器注册表的名称MyRepository
是存储库的名称MyTag
表示要删除的标签。 您还可以选择通过省略--tag MyTag
来删除整个存储库。 可以在此处找到有关az acr repository delete
命令的更多信息: https : //docs.microsoft.com/en-us/cli/azure/acr/repository#delete
这是一个 powershell 脚本,用于删除除标签 MyTag1 和 MyTag2 之外的所有 Azure 容器注册表标签:
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 。
我有一个类似的问题,我想从存储库中删除历史图像,因为我们的配额已达到 100%
我能够通过在 Azure CLI 2.0 中使用以下命令来做到这一点。 该过程执行以下操作:获取标签列表,使用 grep 对其进行过滤并使用 sed 对其进行清理,然后再将其传递给 delete 命令。
获取给定存储库的所有标签
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
作为更新,今天我们发布了多项功能的预览版,包括存储库删除、个人 Azure Active Directory 登录和 Webhook。 史蒂夫
以下来自@christianliebel Azure CLI 的回答会生成unrecognized arguments: --tag MyTag
错误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 文档示例:
我尝试了所有命令,但都没有奏效。我认为它可以堆叠,所以我去了我的门户 azure 并自己删除了我的存储库。 有用
以下命令有助于删除遵循名称或搜索模式的特定图像:-
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'
我已经使用 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'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.