首页 > 解决方案 > 在 swarm 中运行时无法从私有注册表推/拉

问题描述

当我在 swarm 中运行 docker 注册表时:

docker service create \
  --name docker-registry \
  --mount type=bind,src=/some/path,dst=/var/lib/registry \
  -e REGISTRY_HTTP_ADDR=0.0.0.0:5000 \
  --publish 5000:5000 \
  --replicas 2 \
  registry:2

并尝试推送或拉到该注册表(从另一台服务器)它挂起:

$ docker tag hello-world:latest 111.222.333.333:5000/hello-world
$ docker push 111.222.333.333:5000/hello-world
The push refers to a repository [111.222.333.333:5000/hello-world]
428c97da766c: Retrying in 1 second

但是当我将它作为容器运行时它可以工作:

docker run -d \
  -p 5000:5000 \
  --restart=always \
  --name docker-registry \
  -v /some/path:/var/lib/registry \
  registry:2

我将 IP 注册表添加到不安全的注册表中。我究竟做错了什么?

标签: dockerdocker-swarmdocker-registryswarm

解决方案


您已设置--replicas 2服务,并且它们/some/path从主机安装。这意味着:

  • 同一主机上的2 个docker-registry容器访问/some/path
  • 2个docker-registry不同主机上的容器访问/some/path

在这两种情况下,如何docker-registry管理本地存储都与这种配置不兼容。Swarm 将在实例之间分发所有 API 请求,从而导致数据损坏和意外行为。

必须确保始终docker-registry在同一主机上运行。/some/path

对于高可用性配置,文档中有提及。


推荐阅读