在成群运行时无法从私有注册表中推送/拉取

时间:2018-10-27 10:40:04

标签: docker docker-swarm docker-registry 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注册表添加到不安全的注册表中。我在做什么错了?

1 个答案:

答案 0 :(得分:1)

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

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

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

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

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

相关问题