Unable to connect to local docker registry with hostname included

Viewed 533

OS Version : RHEL 8.4 Docker Version : 20.10.6

I have deployed local container registry using command docker run -d -p 5000:5000 --restart=always --name registry registry:2

Used following config /etc/docker/daemon.json for using insecure registries

{
  "insecure-registries" : [ "localhost:5000", "test123:5000" ]
}

My local hostname was set to : test123

But while connecting or pushing images to registry with hostnames, it fails

To test following curl command works with "localhost"

# curl http://localhost:5000/v2/_catalog
{"repositories":["testcontainerimage"]}

But it fails with hostname and times out

# curl http://test123:5000/v2/_catalog

Is there any way/workaround to access registry with hostname "test123" instead of "localhost"


Resolution

As per the Andrew's comment, issue was related to firewall

RHEL8 has changed firewall framework from iptables to nftables. Hence I disabled iptables for docker,

Added "iptables": false in /etc/docker/daemon.json and restarted docker

2 Answers

Doing the curl test with test123: was a good test -- that shows that the problem is with the registry, not the docker client trying to pull from it.

Note that while "localhost" and your hostname both mean "my machine", they are not identical -- localhost is a special ("loopback") network interface that connects only to the local machine, while your hostname will reference your machine's actual network address. This could explain why one works and not the other.

It means that either the registry isn't listening on the network interface, or you have some kind of network filter or firewall that is blocking it. Connection timeouts with no error are typical of firewall behaviour.

I recommend you check your RHEL server's firewall settings. https://www.redhat.com/sysadmin/beginners-guide-firewalld

It might also just be that the name "test123" is not resolving, but if that is the case then Wishwa's suggestion will fix it.

you could add an entry in the /etc/hosts file like below 127.0.0.1 test123

Related