如何在不下载的情况下检索指向最新镜像的docker标签?

时间:2019-01-24 15:22:20

标签: rest docker docker-registry dockerhub

我尝试识别docker标记,它们指向与例如相同的图像。最新版本,因此我可以识别出特定的非“浮动”标签。

我尝试遵循https://docs.docker.com/registry/spec/api/,但根据该文档,我将不得不使用例如https://registry.hub.docker.com/v2/repositories/library/maven/tags/list,如果我没错,但我只运行了https://registry.hub.docker.com/v2/repositories/library/maven/tags/

因此,我找到了一种检索所有标签的方法。但是,现在我想获取摘要而不用这种方式下载图像:

docker pull maven:3.3
docker inspect --format='{{index .RepoDigests 0}}' maven:3.3

因为下载需要很长时间,所以我不想下载所有 图片。

因此,我尝试使用API​​,但是按预期https://registry.hub.docker.com/v2/maven/manifests/3.3无法正常工作。

所以我想知道如何检索清单,以便提取图像的摘要,从而确定匹配的标签。

或者有没有类似的方法

docker image list-similar latest

解决方案的当前状态是

retrieveTags () {
    local IMAGE="$1"

    printf "Retrieve tags [IMAGE=%s]\n" "${IMAGE}" >&2
    local i=1
    while curl -k ${D_REGISTRY_ADDRESS}/v2/repositories/library/${IMAGE}/tags/?page=$i 2>/dev/null | jq -r '."results"[]["name"]' 2>/dev/null
    do 
        i=$((i+1))
        printf "." >&2
    done
    printf "DONE\n" >&2
}

readonly D_IMAGE="maven"
readonly D_TAG="latest"
readonly D_REGISTRY_ADDRESS="${REGISTRY_ADDRESS:-https://registry.hub.docker.com}"

FOUND_TAGS="`retrieveTags maven`" 2>&1
echo "Found tags: ${FOUND_TAGS}"

致谢

0 个答案:

没有答案