原来docker.elastic.co 正在运行一个 V2 docker 注册表,因此它需要 V2 API 命令和令牌身份验证。尝试最初获取标签会导致 401,其中包含有关如何获取令牌的信息:
http https://docker.elastic.co/v2/elasticsearch/elasticsearch/tags/list (566ms)
HTTP/1.1 401 Unauthorized
Connection: keep-alive
Content-Length: 170
Content-Type: application/json; charset=utf-8
Date: Thu, 09 May 2019 15:24:42 GMT
Docker-Distribution-Api-Version: registry/2.0
Www-Authenticate: Bearer realm="https://docker-auth.elastic.co/auth",service="token-service",scope="repository:elasticsearch/elasticsearch:pull"
X-Content-Type-Options: nosniff
{
"errors": [
{
"code": "UNAUTHORIZED",
"detail": [
{
"Action": "pull",
"Class": "",
"Name": "elasticsearch/elasticsearch",
"Type": "repository"
}
],
"message": "authentication required"
}
]
}
使用WWW-Authenticate 中的信息为给定的service 和scope 请求令牌:
http "https://docker-auth.elastic.co/auth?service=token-service&scope=repository:elasticsearch/elasticsearch:pull" (567ms)
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 790
Content-Type: application/json
Date: Thu, 09 May 2019 15:25:37 GMT
{
"token": "some-long-token"
}
最后,使用令牌发出请求:
http -v https://docker.elastic.co/v2/elasticsearch/elasticsearch/tags/list 'Authorization: Bearer some-long-token'
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 1765
Content-Type: application/json; charset=utf-8
Date: Thu, 09 May 2019 15:26:18 GMT
Docker-Distribution-Api-Version: registry/2.0
X-Content-Type-Options: nosniff
{
"name": "elasticsearch/elasticsearch",
"tags": [
"5.0.0-731e78df",
"5.0.0-86a0b164",
"5.0.0-alpha5",
"5.0.0-beta1",
"5.0.0-ccd69424",
"5.0.0-rc1",
"5.0.0",
...
...
...