尝试获取 Docker Hub 目录时范围不足

Insufficient scope when attempting to get Docker Hub catalog

我正在尝试获取 Docker 中心的目录列表,但到目前为止我只是收到一个错误响应。我的理解是我需要通过目录请求传递不记名令牌,所以我首先获取具有相关范围的令牌:

curl -u "username:password "https://auth.docker.io/token?service=registry.docker.io&scope=registry:catalog:*"

(这是使用我的 Docker Hub 帐户中的 username/password)

然后我将返回的令牌传递给注册表:

curl -vL -H "Authorization: Bearer eyJhbGciOiJFUzI1NiIsInR5cCI6I(...)" https://registry-1.docker.io/v2/_catalog

为了响应该请求,我得到:

*   Trying 54.86.130.73...
* Connected to registry-1.docker.io (54.86.130.73) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.docker.io
* Server certificate: RapidSSL SHA256 CA - G3
* Server certificate: GeoTrust Global CA
> GET /v2/_catalog HTTP/1.1
> Host: registry-1.docker.io
> User-Agent: curl/7.43.0
> Accept: */*
> Authorization: Bearer eyJhbGciOiJFUzI1NiIsInR5cCI6I(...)
>
< HTTP/1.1 401 Unauthorized
HTTP/1.1 401 Unauthorized
< Content-Type: application/json; charset=utf-8
Content-Type: application/json; charset=utf-8
< Docker-Distribution-Api-Version: registry/2.0
Docker-Distribution-Api-Version: registry/2.0
< Www-Authenticate: Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="registry:catalog:*",error="insufficient_scope"
Www-Authenticate: Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="registry:catalog:*",error="insufficient_scope"
< Date: Fri, 06 May 2016 23:00:08 GMT
Date: Fri, 06 May 2016 23:00:08 GMT
< Content-Length: 134
Content-Length: 134
< Strict-Transport-Security: max-age=31536000
Strict-Transport-Security: max-age=31536000
<
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"registry","Name":"catalog","Action":"*"}]}]}

...这似乎是要我返回并获得我在上面输入的 URL 的授权。

这应该可行吗?如果是这样,我错过了什么?

我遇到了同样的问题,在 docker 支持下提出了这个问题并得到了以下答案, "The catalog endpoint does not work against Docker Hub because that endpoint actually lists all the repositories on a Registry, and we disabled it as it would list all repositories on Docker Hub."

如果您需要用户名或组织的存储库信息,另一种方法是使用 V1 api。这样做的问题是您需要根据可用的存储库数量进行多次调用。

以下命令将为给定用户名提供可用的存储库:

curl -k -H "Authorization: Basic <encripted username:password>" -H "Accept: application/json" -X GET "https://index.docker.io/v1/search?q=<username>&n=100"

此处 q 是查询,n 是每页要返回的项目数。

通过将 repo 作为参数传递,可以根据您需要的数据进行另一个调用。