来自Docker hub私有注册表的Docker远程api

 0Hey0ne 发布于 2023-01-02 13:01

我正在尝试使用docker远程API 从Docker hub https://registry.hub.docker.com/u/myname/myapp中托管的私有存储库中提取docker映像.该文档不清楚如何在POST请求中指定身份验证凭据

curl -XPOST -H "X-Registy-Auth: base64_encoded_authconfig_object" "http://localhost:4243/images/create?fromImage=myname/myapp"

这也没有详细说明如何生成authconfig.

这里讨论了使用如下结构在基础64编码的json中发送:

{
  "index_url": {
    "username": "string",
    "password": "string",
    "email": "string",
    "serveraddress": "string"
  }
}

但是没有解释什么是index_url和serveraddress.是吗

index_url = https://registry.hub.docker.com/u/myname/myapp
serveraddress = https://registry.hub.docker.com

上面的配置给了我404,可能是注册中心私有仓库没有被识别.

我也试过base 64编码我的〜/ .dockercfg的内容

{
  "https://index.docker.io/v1/": {
    "auth":"xxxxxxxxxxxxxxxxxxx==",
    "email":"myname@myemail.com"
  }
}

你能告诉我如何生成base64编码的authconfig对象并使上面的curl命令工作.

提前致谢

Docker版本

Client version: 0.11.1
Client API version: 1.11
Go version (client): go1.2.1
Git commit (client): fb99f99
Server version: 0.11.1
Server API version: 1.11
Git commit (server): fb99f99
Go version (server): go1.2.1

mbarthelemy.. 11

我遇到过同样的问题.

这是您应该用于传递凭据的"原始" AuthConfig对象:

{
  "username":"your_registry_username_or_email",
  "password":"*****",
  "auth":"",    // leave empty
  "email":"your@email.tld"
}

然后,您必须使用Base64对其进行"编码" .

您没有说出您正在使用的语言,但如果需要,这个非常棒的网站将让您只需点击一下即可对您的对象进行编码.或者,从shell:

echo '{"username":"username","password":"*****", "auth":"","email":"your@email.tld"}' | base64


然后,只需将编码值传递给标头:

X-Registry-Auth: eyJ1c2VybmFtZSI6InlvdXJfcmVnaXN0cnlfdXNlcm5hbWVfb3JfZW1haWwiLCJwYXNzd29yZCI6IioqKioqIiwiYXV0aCI6IiIsImVtYWlsIjoieW91ckBlbWFpbC50bGQifQ==

这是一个使用curl和的工作示例

r.getitlive.io上提供的注册表

停靠在'192.168.60.10:8888'的码头守护进程:

curl -X POST  -d ""  \
  -H "X-Registry-Auth: eyJ1c2VybmFtZSI6InlvdXJfcmVnaXN0cnlfdXNlcm5hbWVfb3JfZW1haWwiLCJwYXNzd29yZCI6IioqKioqIiwiYXV0aCI6IiIsImVtYWlsIjoieW91ckBlbWFpbC50bGQifQ==" \
  'http://192.168.60.11:8888/images/create?fromImage=r.getitlive.io/cool/repo&tag=latest'

注意:通过将远程注册表端点/ URL放在serveraddressAuthConfig对象的字段中,我无法使其工作.这就是我将注册表主机添加到fromImage=参数的原因.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有