When running Java Spring directly on the Nomad client, and going to the address in the browser, it works fine. When I run it via the Java driver with bridged networking I get the following exception. I did not specify any DNS configuration in the job spec so curious why the isolation layer is complaining about the server hostname when the actual host isn’t? And what do I need to do to get around this?
java.net.UnknownHostException: nomad-client-0: nomad-client-0: Temporary failure in name resolution
Adding the below DNS block seems to resolve the “Temporary failure in name resolution” issue, but it raises a separate java.net.UnknownHostException: ip-10-0-10-163: ip-10-0-10-163: Name or service not known instead now. I can resolve external hostnames now, just not the local one…
group "java" {
network {
mode = "bridge"
port "http" {
to = 8080
}
dns {
servers = []
options = []
searches = []
}
}
The above DNS block sets the /etc/resolv.conf to the following.
The Java application is failing to get localhost using the code snippet before. The /etc/hosts and /etc/resolv.conf files on the host and the “container” (cgroup + namespaces) match.
InetAddress ip = InetAddress.getLocalHost();
int serverPort = serverProperties.getPort();
return new Greeting(String.format(template, ip.getHostAddress() + ":" + String.valueOf(serverPort)));
Running certain hostname commands give the same error, while others don’t (e.g. hostname -I)
nobody@ip-10-0-10-163:/$ hostname -i
hostname: Name or service not known
nobody@ip-10-0-10-163:/$ hostname -f
hostname: Name or service not known
Very confused why this works fine on the host but not in the “container”. Trying to get a PoC of Consul and Nomad working for my company but it is getting snagged on seemingly trivial problems =(.
Bumping this thread, would love to know if anyone has found a solution to this. It is indeed quite surprising that this has not been discussed before.
A very simple usecase that I am struggling with…
I’m running nomad in AWS, and my spring application running on a java driver is not able to hit RDS using its hostname. If I set the network mode to host, and don’t use a sidecar, things work fine.
I can also see that a docker container running in bridge mode with a sidecar proxy has no problems resolving the hostname for RDS on the same client.
I could suggest something:
you could set it up as a raw_exec instead of the java driver.
A small script using the template block could be the stub which starts the application.
The health-checks, etc. would be then much simpler as everything is on the machine OS itself.