我想检查我的映像是否存在于docker hub上。 我找到2种解决方案。
1)
docker pull alpine:invalid > /dev/null && echo "success" || echo "failed"
2)
# set username and password
UNAME="user"
UPASS="password"
function docker_tag_exists() {
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${UNAME}'", "password": "'${UPASS}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token)
EXISTS=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/$1/tags/?page_size=10000 | jq -r "[.results | .[] | .name == \"$2\"] | any")
test $EXISTS = true
}
if docker_tag_exists library/nginx 1.7.5; then
echo exist
else
echo not exists
fi
解决方案之一是bash脚本,解决方案2使用jq,但我不想安装jq。
是否存在一种通过简单卷曲检查图像是否存在的方法?
像这样的港口
curl -u $USERNAME:$PASSWORD -s -o /dev/null -I -w \"%{http_code}\" -X GET \"http://${REGISTRY_HOST}/api/repositories/images%2F${repo_name}/tags/${image_tag}\"