Docker-swarm自动从私人docker-registry中提取丢失的图像

时间:2016-10-14 15:33:16

标签: authentication docker docker-registry docker-swarm

我们有一个docker-swarm集群。管理器节点将凭据保存到我们的私有docker注册表。当我们在其他节点上启动新容器时,可能需要从私有docker注册表中提取映像。

有没有办法告诉crate container命令拉取图像(如果节点上已经不存在)并为其提供凭据?

例如:我们想从swarm管理器(具有私有docker注册表的凭据)调用以下命令:

docker create -e contraint:server==app docker.exampleRegistry.com/path/image:1.0.0

这应该拉动图像并在另一个节点(标记为app)上启动容器。 docker注册表docker.exampleRegistry.com是私有的。但我们得到:

Error response from daemon: unauthorized: authentication required

1 个答案:

答案 0 :(得分:0)

知道了! docker cli可能无法做到这一点(我们的java驱动程序也不能)但docker远程API可以使用X-Registry-Auth头来提供凭据:

curl -v -X POST -H "Content-Type: application/json"\
-H "X-Registry-Auth: <base64ecoded({"username": "string", "password": "string", "email": "string", "serveraddress" : "string", "auth": ""})>"\
-d '{"Image": "docker.exampleRegistry.com/path/image:1.0.0", "Env": ["contraint:server==app"]}'\
https://localhost:2376/containers/create?name=container \
--key path_to_key \
--cacert path_to_ca

https://github.com/docker/docker/blob/master/docs/reference/api/docker_remote_api.md#authentication