Can't push/pull from private registry when run in swarm

Viewed 425

When I'm running docker registry in swarm:

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

and trying to push or pull to that registry (from another server) it hangs:

$ 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

but it works when I run it as container:

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

I added IP registry to insecure registries. What am I doing wrong?

1 Answers

You have set --replicas 2 for service, and they mount /some/path from host. That means either:

  • 2 docker-registry containers on the same host accesses /some/path
  • 2 docker-registry containers on different hosts accesses /some/path

In both cases, how docker-registry manages the local storage, is not compatible with such configuration. Swarm will distribute all API requests among instances, causing data corruption and unexpected behavior.

One have to make sure that docker-registry running on the same host with same /some/path always.

For high availability configurations, there are mentions in documentation.

Related