How to access a local docker registry from another container on a user defined bridge network

Viewed 214

I'm trying to setup a test environment so I can perform jenkins docker builds on an agent and push the resulting image to a local registry. I want to use a local registry for speed.

I'm running docker desktop on Windows 10 with a WSL2 backend.

I have Jenkins running in a container and I have a build agent running in another container, both are using a named bridge network and as such resolve each other by name. The build part is all working, I can build my images and push to docker hub from my build agent.

If I run the docker registry in a container as described in the docs https://hub.docker.com/_/registry/

docker run -d --restart=always --name registry -p 5000:5000 registry:2.7

I can push/pull to/from that local registry from my docker host.

When I run the registry container using the same network as Jenkins and the build agent, I don't publish the port to the host.

docker run -d --restart=always --name registry --network jenkins registry:2.7

At this point I was expecting to be able to use the registry from my build agent. When I attempt to push my image I get errors.

When I use

docker push registry:5000/myimage

The response is very slow an looks like this

The push refers to repository [registry:5000/connector]
Get https://registry:5000/v2/: dial tcp: lookup registry on 192.168.65.5:53: read udp 192.168.65.4:47451->192.168.65.5:53: i/o timeout

However if I ping registry I see this

PING registry (172.18.0.6) 56(84) bytes of data.
64 bytes from registry.jenkins (172.18.0.6): icmp_seq=1 ttl=64 time=0.097 ms

I don't understand why the addresses reported are different and I don't recognise the 192.168.65 network.

The same happens if I run the registry without the network (using the default bridge) and attempt to connect to it from another container on the default bridge, although in this scenario I have to use the IP address as the name doesn't resolve.

I'm stumped, I was expecting to run the registry in the container on the named network and gain access to it from my build agent so I can push the image locally and save time as its a lot faster than pushing to the docker hub.

Can anyone help me achieve that?

Thanks

0 Answers
Related