![](/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.