对于直接来自Docker Hub的Docker图像,我可以通过击中其存储库API来检索图像的当前标签列表。例如,https://registry.hub.docker.com/v1/repositories/python/tags
将为我提供可以与docker pull python:<tag>
一起使用的标签列表。
用于弹性搜索,我正在使用他们的官方存储库,并且可以使用 docker pull docker.elastic.co/elasticsearch/elasticsearch:6.4.0
但是,我不知道如何从该存储库中获取标签列表。我尝试了
https://docker.elastic.co/elasticsearch/elasticsearch/tags
https://docker.elastic.co/v1/repositories/elasticsearch
https://docker.elastic.co/v2/repositories/elasticsearch/elasticsearch/_manifests/tags
..和其他几个变体。什么URL/API端点是Docker命令行工具将其转换为后端请求上的存储库/图像名称?
事实证明,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",
...
...
...
您可以尝试以相同的方式为Python获取标签/可用版本列表。
示例:https://registry.hub.docker.com/v1/repositories/elasticsearch/tags
样本出口:[{"layer": "", "name": "1"}, {"layer": "", "name": "1-alpine"}]
因此,您要做的事情,您将在Shell脚本中提供标签列表,并要求他们选择。然后,基于此,您将在自定义Docker文件中进行Docker拉动并运行这些命令吗?