2

This is very similar to the following question, however the solution/answer to this previous question doesn't solve the problem.

In my case I'm not connecting to MySQL specifically, however trying to resolve www.google.com results in the same UnknownHostException only within the container. When I run from just the JVM and not within a container on my MAC, there's no issues in resolving.

Same scenario where: InetAddress ip = InetAddress.getByName("www.google.com");

I've tried the following suggested fix:

RUN echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf

as well as..

RUN echo "hosts: files dns" >> /etc/nsswitch.conf"

Neither seem to do the trick..

Are there any other suggestions out there, anything I'm missing in addition to the above suggestions?

Thanks in advance.

byte-crunch
  • 271
  • 2
  • 13

1 Answers1

0

It turns out the solution was fairly simple, and there's a couple options..

For you experts, this is probably funny, but at least its one more idea for the next guy..

So what I've found is I can specify the DNS on each of the nodes in my swarm via:

/etc/docker/daemon.json

{
    "dns": ["10.0.0.2", "8.8.8.8", etc.. ]
}

After setting this on each node, specifically 8.8.8.8 for google's DNS, then "google.com" resolved and no prob. Note that its a google specific DNS, but its provides a public DNS. Yahoo, Amazon, etc all resolved.. The 10.0.0.2 address would be any other DNS you want to specify, and you can specify multiples.

This came from the following post: Fix Docker's networking DNS config

However, it even easier if you want to specify the DNS via your compose/stack file.

Rather than go to each node in your swarm and update the daemon.json DNS entries, you can specify the DNS directly in your compose.

version: '3.3'

services:
  my-sample-service:
    image: my-repo/my-sample:1.0.0
    ports: 8081:8080
    networks:
      - my-network
    dns:
      - 10.0.0.1 #this would be whatever your say internal DNS is priority 1
      - 10.0.0.2 #this would be whatever other DNS you'd provide  priority 2
      - 8.8.8.8  #default google address, even though docker specifies this
                 #as a default, it wasn't working until I specifically set it
                 #this would be the last one checked if no resolution happened
                 #on the first two.
byte-crunch
  • 271
  • 2
  • 13