Docker远程api从Docker中心私有注册表 [英] Docker remote api pull from Docker hub private registry
问题描述
我试图从Docker中心托管的私人存储库中引用Docker图像 https: //registry.hub.docker.com/u/myname/myapp ,使用docker远程API。 doc 不清楚如何指定认证凭据这样的POST请求
I'm trying to pull docker images from a private repository hosted in Docker hub https://registry.hub.docker.com/u/myname/myapp like this using the docker remote API. The doc is not clear as to how to specify the authentication credentials in a POST request like this
curl -XPOST -H "X-Registy-Auth: base64_encoded_authconfig_object" "http://localhost:4243/images/create?fromImage=myname/myapp"
此还没有详细说明authconfig的生成方式。
This also does not elaborate on how exactly the authconfig is generated.
这个谈论在基地64发送编码的json使用这样的结构:
This talks about sending in a base 64 encoded json with a structure like this:
{
"index_url": {
"username": "string",
"password": "string",
"email": "string",
"serveraddress": "string"
}
}
但是没有解释什么是index_url和服务器地址。是否
But doesnt explain what is index_url and serveraddress. Are they
index_url = https://registry.hub.docker.com/u/myname/myapp
serveraddress = https://registry.hub.docker.com
上述配置给了我404,大概是注册中心私人回购未被识别。
The above configurations give me 404, probably the registry hub private repo is not being recognized.
我还尝试过将基本的64编码,我的〜/ .dockercfg的内容
I also tried base 64 encoding the contents of my ~/.dockercfg
{
"https://index.docker.io/v1/": {
"auth":"xxxxxxxxxxxxxxxxxxx==",
"email":"myname@myemail.com"
}
}
你能告诉我如何生成base64编码的authconfig对象,并得到上面的curl命令。
Could you tell me how to generate the base64 encoded authconfig object and get the above curl command working.
提前感谢
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
推荐答案
我有同样的问题。
这是您应该用于传递凭据的raw AuthConfig 对象:
Here's the "raw" AuthConfig object that you should use to pass the credentials:
{
"username":"your_registry_username_or_email",
"password":"*****",
"auth":"", // leave empty
"email":"your@email.tld"
}
然后您必须使用 Base64的即可。
You then have to "encode" it using Base64.
您没有告诉您使用哪种语言,但如果需要,这个真棒网站将让您一键编码您的对象。或者,从shell:
You didn't tell what language you're using, but if needed, this awesome site will let you encode your object in one click. Or, from a shell:
echo '{"username":"username","password":"*****", "auth":"","email":"your@email.tld"}' | base64
然后,刚刚所编码的值传递给标头:
Then, just pass the encoded value to the header:
X-Registry-Auth: eyJ1c2VybmFtZSI6InlvdXJfcmVnaXN0cnlfdXNlcm5hbWVfb3JfZW1haWwiLCJwYXNzd29yZCI6IioqKioqIiwiYXV0aCI6IiIsImVtYWlsIjoieW91ckBlbWFpbC50bGQifQ==
这是一个使用 curl
和
- 在r.getitlive.io可用的注册表
- 在'192.168.60.10:8888'聆听的docker守护进程:
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放在 AuthConfig对象的serveraddress
字段。这就是为什么我将注册表主机添加到 fromImage =
参数。
Note : I couldn't make it work (yet) by putting the remote registry endpoint/URL in the serveraddress
field of the AuthConfig object. That's why I'm adding the registry host to the fromImage=
parameter.
这篇关于Docker远程api从Docker中心私有注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!