Docker stack deploy无法拉取镜像

132次阅读
没有评论

问题描述

在使用Ansible通过SSH启动docker stack deploy时遇到了问题。即使直接从管理节点启动也存在相同的问题。用户在启动命令中使用了--with-registry-auth选项,并且在.docker/config.json文件中定义了访问私有镜像仓库的凭据。问题首次出现在执行docker stack ps test-stack命令时,错误信息如下:

... Shutdown            Rejected 11 minutes ago      "No such image: myregistry.com:12345/myimage:mytag"

工作节点没有上传用户想要的镜像。在工作节点的日志中,用户看到了以下内容:

Jan 31 11:22:24 myhost dockerd[1149]: time="2019-01-31T11:22:24.574302458+01:00" level=warning msg="Error getting v2 registry: Get https://myregistry.com:12345/v2/: http: server gave HTTP response to HTTPS client"
Jan 31 11:22:24 myhost dockerd[1149]: time="2019-01-31T11:22:24.574342640+01:00" level=info msg="Attempting next endpoint for pull after error: Get https://myregistry.com:12345/v2/: http: server gave HTTP response to HTTPS client"
Jan 31 11:22:24 myhost dockerd[1149]: time="2019-01-31T11:22:24.618063948+01:00" level=info msg="Attempting next endpoint for pull after error: unauthorized: authentication required"
Jan 31 11:22:24 myhost dockerd[1149]: time="2019-01-31T11:22:24.618121224+01:00" level=error msg="pulling image failed" error="unauthorized: authentication required" module=node/agent/taskmanager node.id=rarbt9afb16y7j77bfwiacby2 service.id=ej4y7wbwp539u7mmmhfashz93 task.id=c1uy2gnwdcmibp6l2p9rfxcsh
Jan 31 11:22:24 myhost dockerd[1149]: time="2019-01-31T11:22:24.618840324+01:00" level=error msg="fatal task error" error="No such image: myregistry.com:12345/myimage:mytag" module=node/agent/taskmanager node.id=rarbt9afb16y7j77bfwiacby2 service.id=ej4y7wbwp539u7mmmhfashz93 task.id=c1uy2gnwdcmibp6l2p9rfxcsh
Jan 31 11:22:29 myhost dockerd[1149]: time="2019-01-31T11:22:29.548642584+01:00" level=warning msg="failed to deactivate service binding for container test-stack_myservice.1.c1uy2gnwdcmibp6l2p9rfxcsh" error="No such container: test-stack_myservice.1.c1uy2gnwdcmibp6l2p9rfxcsh" module=node/agent node.id=rarbt9afb16y7j77bfwiacby2

问题是,当用户在工作节点上执行docker pull myregistry.com:12345/myimage:mytag命令时,可以成功拉取镜像,没有任何问题。但是使用docker stack deploy命令时却无法拉取镜像,尽管使用了--with-registry-auth选项。

解决方案

请注意以下操作注意版本差异及修改前做好备份。

方案1

问题可能是由于工作节点没有正确的凭据访问docker镜像仓库。请确保在每个工作节点上正确配置了访问私有镜像仓库的凭据。以下是解决方案的步骤:
1. 在每个工作节点上,打开终端并登录到工作节点。
2. 打开.docker/config.json文件,确保其中的凭据正确配置。
3. 如果凭据不正确,请根据实际情况更新凭据。
4. 重启docker服务以使更改生效。
5. 重新执行docker stack deploy命令,检查是否能够成功拉取镜像。

方案2

如果使用--with-registry-auth选项,通常不需要在每个工作节点上设置凭据,因为凭据会由管理节点传递给工作节点。
在我的情况下,问题是我使用了自签名证书来访问私有docker镜像仓库。我在主节点上正确配置了证书,但在工作节点上没有配置,因此在工作节点上连接到镜像仓库时会引发”x509: certificate signed by unknown authority”错误。修复工作节点上的证书错误解决了问题,无需在工作节点上设置镜像仓库的凭据。

方案3

如果以上解决方案都无法解决问题,可以尝试以下步骤:
1. 在每个工作节点上,打开终端并登录到工作节点。
2. 执行以下命令以确保工作节点可以访问镜像仓库:
bash
docker login myregistry.com:12345

根据提示输入正确的凭据。
3. 重新执行docker stack deploy命令,检查是否能够成功拉取镜像。

以上是解决问题的几种可能方案,请根据实际情况选择适合的方案进行尝试。如果问题仍然存在,请提供更多详细信息以便进一步帮助解决。

正文完