-
-
Notifications
You must be signed in to change notification settings - Fork 16.3k
DNS resolution in a Java Docker container fails #6844
Copy link
Copy link
Closed
Description
Netty version: 4.1.12.Final
Docker image: openjdk:8-jre
Context:
Running DNS resolution in a Java docker container fails. DNS resolution should complete successfully and return the IP address of the sibling docker container. Instead it throws the following exception:
Exception in thread "main" java.util.concurrent.ExecutionException: java.net.UnknownHostException: failed to resolve 'recomp-hdb' after 3 queries
at io.netty.util.concurrent.AbstractFuture.get(AbstractFuture.java:41)
at TestNetty.main(TestNetty.java:15)
Caused by: java.net.UnknownHostException: failed to resolve 'recomp-hdb' after 3 queries
at io.netty.resolver.dns.DnsNameResolverContext.finishResolve(DnsNameResolverContext.java:688)
at io.netty.resolver.dns.DnsNameResolverContext.tryToFinishResolve(DnsNameResolverContext.java:620)
at io.netty.resolver.dns.DnsNameResolverContext$3.operationComplete(DnsNameResolverContext.java:313)
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:507)
...
DNS resolution with plain Java code works as expected and returns the IP address.
The Netty-based code that throws the exception:
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.resolver.dns.DnsNameResolverBuilder;
import io.netty.resolver.dns.DnsNameResolver;
import io.netty.resolver.dns.DnsServerAddresses;
public class TestNetty {
private static NioEventLoopGroup bossGroup = new NioEventLoopGroup();
public static void main(String[] args) throws Exception {
DnsNameResolver res = new DnsNameResolverBuilder(bossGroup.next())
.channelType(NioDatagramChannel.class)
.build();
System.out.println(res.resolve("recomp-hdb").await().get());
}
}
The plain Java code which works fine:
import java.net.InetAddress;
public class Test {
public static void main(String args[]) throws Exception {
InetAddress address = InetAddress.getByName("recomp-hdb");
System.out.println(address.getHostAddress());
}
}
Steps to reproduce:
- Create a docker compose file that defines two docker containers, one of which is based on openjdk image.
- Build the code shown above, changing the name of the sibling container according to your docker compose.
- Copy in the code to the java container and run.
- The plain java code will show the correct response. The netty-based code will throw the exception as above.
Reactions are currently unavailable