Moby: 无法理解如何从私有存储库中获取 image_id 或其他信息

创建于 2017-03-15  ·  3评论  ·  资料来源: moby/moby


错误报告信息

描述

我们在 docker hub 上使用 docker 私有存储库,当有更多 10 个图像时。

我们希望从 docker hub 获取 docker 图像信息,以便能够比较 docker hub 上构建的和当前呈现的图像。

我尝试通过运行我在谷歌中找到的命令来使用 curl 来获取身份验证令牌。

看起来像:

UNAME="exampleuser"
UPASS="examplepass"
PRODUCT="examplecompany"
REPOSITORY="$PRODUCT"
SERVICE="exampleservice"

我尝试通过以下方式获取令牌:

TOKEN=$(curl -u $UNAME:$UPASS "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$REPOSITORY:pull&account=$UNAME" | jq -r .token)

TOKEN=$(curl -u $UNAME:$UPASS "https://auth.docker.io/token?service=index.docker.io&scope=repository:$REPOSITORY:pull&account=$UNAME" | jq -r .token)

TOKEN=$(curl -u $UNAME:$UPASS "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$REPOSITORY:pull&account=$UNAME&offline_token=true" | jq -r .token)

TOKEN=$(curl -u $UNAME:$UPASS "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$REPOSITORY:$SERVICE:pull&account=$UNAME&offline_token=true" | jq -r .token)

TOKEN=$(curl -u $UNAME:$UPASS "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$REPOSITORY:$SERVICE&account=$UNAME&offline_token=true" | jq -r .token)

在所有情况下,我都会通过以下方式获得一些令牌,尝试从我的私人存储库中获取清单:

1.

REPO="$PRODUCT/$SERVICE"
TAG=latest
REGISTRY=https://registry-1.docker.io/v2

URI="$REGISTRY/$REPO/manifests/$TAG"
echo URI=$URI
MANIFEST="`curl -skL -o /dev/null -D- $URI`"
CHALLENGE="`grep "Www-Authenticate" <<<"$MANIFEST"`"
if [[ CHALLENGE ]]; then
    IFS=\" read _ REALM _ SERVICE _ SCOPE _ <<<"$CHALLENGE"
    echo REALM is $REALM
    echo SERVICE is $SERVICE
    echo SCOPE is $SCOPE
    TOKEN="`curl -skL "$REALM?service=$SERVICE&scope=$SCOPE"`"
    IFS=\" read _ _ _ TOKEN _ <<<"$TOKEN"
    echo TOKEN is $TOKEN
    MANIFEST="`curl -isk -X GET -H "Authorization: Bearer $TOKEN" $URI`"
    echo "RESPONSE is $MANIFEST"
fi

2.

curl -s -D - -H  "Authorization: Bearer ${TOKEN}" -H "Accept: application/vnd.docker.distribution.manifest.v2+json" https://index.docker.io/v2/repositories/$PRODUCT/$SERVICE/manifests/latest

总是得到

RESPONSE is HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
Docker-Distribution-Api-Version: registry/2.0
Www-Authenticate: Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="examplecompany/exampleservice:pull",error="insufficient_scope"
Date: Wed, 15 Mar 2017 16:15:52 GMT
Content-Length: 155
Strict-Transport-Security: max-age=31536000

{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"repository","Class":"","Name":"examplecompany/exampleservice","Action":"pull"}]}]}

如何更正从 docker hub 获取我需要的所有信息?

当我尝试通过以下方式获取标签时

REPO_LIST=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/${PRODUCT}/?page_size=10000 | jq -r '.results|.[]|.name')

我没有问题。

此外,我找不到任何工作方式来做我想做的事。

重现问题的步骤:

  1. 在 hub.docker.com 上拥有私人图像
  2. 获取身份验证令牌
  3. 尝试从 hub.docker.com 获取清单信息或其他图像信息

描述您收到的结果:

{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"repository","Class":"","Name":"examplecompany/exampleservice","Action":"pull"}]}]}

描述您期望的结果:

包含当前在 docker hub 图像上显示的信息的 Json。

aredistribution kinquestion

所有3条评论

https://github.com/docker/docker/issues/29257#issuecomment -266121974 上的讨论大概跟这里有关

@westsouthnight ,也许这个脚本可以帮助你: https : //gist.github.com/cirocosta/fb6b90cb7651ff21eda4838a73e3710b
它在检索令牌时不使用-u来执行基本身份验证,但我使用私有存储库进行了测试并将-uget_token() {确实有效:使用私有注册表我只有在使用-u才能检索注册表。

  curl \
    -u user:pass \
    --silent \
    "https://auth.docker.io/token?scope=repository:$image:pull&service=registry.docker.io" \
    | jq -r '.token'

让我知道这是否有帮助👍

让我结束这个问题,因为 GitHub 问题跟踪器并不是真正的通用支持论坛,
但用于报告错误和功能请求。 对于其他类型的问题,请考虑使用其中之一;

这个问题也与此存储库中的源代码没有直接关系,而是与 Docker Hub(以及在那里使用的身份验证)相关。 但请随意继续对话👍

此页面是否有帮助?
0 / 5 - 0 等级