检查docker hub上是否已存在image:tag组合
作为bash脚本的一部分,我想检查docker hub上是否存在特别的docker image:tag组合。同样,它将是一个私有存储库。
即伪代码将是这样的:
tag = somethingif image:tag already exists on docker hub:
Do nothing
else
Build and push docker image with that tag
回答:
请试试这个
function docker_tag_exists() { curl --silent -f -lSL https://index.docker.io/v1/repositories/$1/tags/$2 > /dev/null
}
if docker_tag_exists library/nginx 1.7.5; then
echo exist
else
echo not exists
fi
更新:
如果使用Docker Registry
v2(基于此):
# set username and passwordUNAME="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
以上是 检查docker hub上是否已存在image:tag组合 的全部内容, 来源链接: utcz.com/qa/420348.html