Docker-CE UnknownHostException Container DNS

Afternoon,

I’m currently running a PoC of a product which uses Docker-CE 18.06.1 to pull down 2 images from Docker registry and run on two containers within an isolated_nw. Creation of the containers and the network is done via Docker-compose (v1.22)

The host is a Linux VM (Red Hat Enterprise Linux Server release 7.5 (Maipo))

I’ve been struggling for around 6 weeks now with a really frustrustrating issue where one container (sk4_tomcat_1) can’t communicate to the other container (sk4_postgres_1) via DNS name but can ping the other container via it’s virtual network IP (172.18.0.2).

Ultimately though this results in UnknownHostException: sk4_postgres each time the sk4compose.service is started.

I can see from the docker network inspect that both containers have joined and Aliases have been correctly set up for container name and sk4_postgres but for some reason DNS doesn’t seem to be working.

“sk4_isolated_nw”: {
“IPAMConfig”: null,
“Links”: null,
“Aliases”: [
“77940b301482”,
“sk4_postgres”
],

I have also created a daemon.json file which contains our local DNS nameservers as public DNS servers are unreachable.

{
“dns”: [“10.99.124.6”,“10.99.124.7”]
}

I can get around the issue by changing the name sk4_postgres to the containers IP in my applications persistence.xml but this only causes the application to fail at the next stage where it needs to resolve a public DNS name which then fails again with UnknownHostException.

It looks like i’m really struggling with DNS at the moment within my companies network but everyone has drawn a blank at the moment.

Thanks very much.

Mike

Hi :slight_smile:

On your tomcat container, can you try and “cat /etc/hosts”, and paste the output?

docker exec sk4_tomcat_1 cat /etc/hosts

Hi Martin,

Thanks for your response. I’ve added the output below where 172.18.0.3 is the IP address of this specific container.

127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.18.0.3 360173c28cb5