Access Docker Containers Host by DNS name

Viewed 954

From my Spring Boot application deployed as a Docker container I need to be able to access the parent node (within a Swarm) by some kind of docker-exposed DNS name so that I can add it to a configuration file and was wondering if there was a DNS name exposed automatically by Docker for this purpose?

Another container that is scheduled on the same host running in "network_mode: host" is running Consul and advertising on port 8500 (real IP is 192.168.1.233).

If I run netstat on the Swarm node (ip 192.168.1.233) I can see it's listening on port 8500:

# netstat -anp | grep 8500

tcp6       0      0 :::8500                 :::*                    LISTEN      25010/docker-proxy

I want to be able to define a connection string as configuration in the Spring Boot app on the swarm node to the local instance of Consul sheduled on the same physical host as the Spring Boot app.

If I refer to "localhost" within the Spring Boot container then there's nothing listening on the 8500 port, proven by running this after shelling into the Spring Boot container (using a sample Consul API call)

# wget http://localhost:8500/v1/status/leader

Connecting to localhost:8500 (127.0.0.1:8500)
wget: can't connect to remote host (127.0.0.1): Connection refused

I've also tried using "host.docker.internal" but that doesn't work:

# ping host.docker.internal

ping: bad address 'host.docker.internal'

The hosts are all Centos 7 hosts, and Docker version 18.09.1, build 4c52b90.

The firewalld service is disabled on all hosts.

Thanks for your help!

0 Answers
Related