如何从IBM Cloud Private 2.1.0中的注册表中删除图像?在1.2中,您可以从UI中删除图像。如何在当前版本中完成?
答案 0 :(得分:1)
我编写了一个脚本来帮助通过CLI删除图像。它允许您根据jq
CLI包含的模式删除ICP注册表中的图像。此脚本旨在在ICP主节点上运行。保存片段,chmod + x,更新你的信誉的vars并享受!
示例调用:
./ remove-registry-image.sh label
中的特定图像标签
结果 ::删除名称空间或图像中包含该标签的所有图像
./remove-registry-image.sh namespace / image-label
结果 ::删除位于命名空间
#!/bin/bash
# ----------------------------------------------------------------------------------------------------\\
# Description:
# A basic script port to delete registry images on an ICP Cluster
# Fork of https://gist.github.com/mohamed-el-habib/26d26dddaf3dcefcc0e6bdd8a15bd681
# Reference: https://www.ibm.com/support/knowledgecenter/en/SSBS6K_2.1.0/apis/docker_registry_api.html
#
# usage ./remove-registry-image.sh filterString
#
# ./remove-registry-image.sh nameSpace/textString
#
# ----------------------------------------------------------------------------------------------------\\
set -e
##########
# Colors##
##########
Green='\x1B[0;32m'
Red='\x1B[0;31m'
Yellow='\x1B[0;33m'
Cyan='\x1B[0;36m'
no_color='\x1B[0m' # No Color
beer='\xF0\x9f\x8d\xba'
delivery='\xF0\x9F\x9A\x9A'
beers='\xF0\x9F\x8D\xBB'
eyes='\xF0\x9F\x91\x80'
cloud='\xE2\x98\x81'
crossbones='\xE2\x98\xA0'
litter='\xF0\x9F\x9A\xAE'
fail='\xE2\x9B\x94'
harpoons='\xE2\x87\x8C'
tools='\xE2\x9A\x92'
present='\xF0\x9F\x8E\x81'
#############
export ICPUSER=admin
export ICPPW=admin
# Get the variables
clear
echo -e "${tools} Welcome to the delete registry script for an IBM Cloud Private Cluster v2 Docker Registry"
if [ "${OS}" == "rhel" ]; then
sudo yum install epel-release -y
sudo yum install jq -y
else
sudo apt-get -qq install jq -y
fi
dockerRegistry='mycluster.icp'
dockerRegistryPort='8500'
user="$ICPUSER:$ICPPW"
imagesFilter="$1"
# get the list of images names that match the filter
CATALOG_TOKEN=$(curl --cacert $HOME/.kube/kubecfg.crt -u ${user} -ks "https://${dockerRegistry}:8443/image-manager/api/v1/auth/token?service=token-service&scope=registry:catalog:*" | jq -r '.token')
images=$(curl --cacert $HOME/.kube/kubecfg.crt -ks -H "Authorization: Bearer ${CATALOG_TOKEN}" "https://${dockerRegistry}:${dockerRegistryPort}/v2/_catalog" | jq -r '.repositories[]? | select(. | contains("'${imagesFilter}'")) ')
for image in $images ; do
# get the list of tags for each image
TAG_TOKEN=$(curl --cacert $HOME/.kube/kubecfg.crt -u ${user} -ks "https://${dockerRegistry}:8443/image-manager/api/v1/auth/token?service=token-service&scope=repository:${image}:*" | jq -r '.token')
tags=$(curl --cacert $HOME/.kube/kubecfg.crt -ks -H "Authorization: Bearer ${TAG_TOKEN}" "https://${dockerRegistry}:${dockerRegistryPort}/v2/${image}/tags/list" | jq -r .tags[]?)
for tag in $tags ; do
echo "${image}:${tag}"
# get the digest of the image:tag
digest=$(curl -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -v --cacert $HOME/.kube/kubecfg.crt -ks -H "Authorization: Bearer ${TAG_TOKEN}" "https://${dockerRegistry}:${dockerRegistryPort}/v2/${image}/manifests/${tag}" 2>&1 | grep -e "Docker-Content-Digest:*" | awk '{ sub(/\r/,"",$3) ; print $3 }')
if [ -z $digest ] ; then
echo "${image}:${tag} not found"
else
echo -e "${litter} Deleting ${image}:${tag}:${digest}"
curl -XDELETE -w "[%{http_code}]\n" --cacert $HOME/.kube/kubecfg.crt -ks -H "Authorization: Bearer ${TAG_TOKEN}" "https://${dockerRegistry}:${dockerRegistryPort}/v2/${image}/manifests/${digest}"
fi
echo "...."
done
done
if [ -n "${images}" ]; then
echo -e "${fail} No images matching provided filterString (${imagesFilter}) found"
else
echo -e "${beers} Congrats! All images matching chosen filterString (${imagesFilter}) have been deleted"
fi
答案 1 :(得分:0)
是的,在2.1.0中删除图像无法通过UI完成。 UI将在以后的版本中恢复该功能。 对于即将发布的版本,您可以通过API执行此操作。知识中心文档将为此更新信息。
答案 2 :(得分:-1)
首先列出它们:
docker images
删除其中一个:
docker rmi -f the-image-id
删除所有这些:
docker rmi -f $(docker images -a -q)