I sent a request to "container 1" from my localhost, which is supposed to call "container 2" in a synchronous fashion and return a response to the request made from the localhost. The request is received by container 1, but it fails to communicate with container 2.
PS: I am able to login to container 1 and ping container 2 ("ping metadata") using it's network alias without any issues.
Dockerfile:
FROM java:8
WORKDIR /
ADD /target/api-1.0-jar-with-dependencies.jar api-1.0.jar
EXPOSE 8000 9000
CMD java -jar api-1.0.jar
Docker command:
docker run --network backend -d -p 8000:8000 api
Java code where exception is thrown:
String target = "metadata:9000";
ManagedChannel channel = ManagedChannelBuilder.forTarget(target)
.usePlaintext()
.build();
MetadataGrpc.MetadataBlockingStub blockingStub = MetadataGrpc.newBlockingStub(channel);
MetadataIO.Response response = blockingStub.create(req);
responseObserver.onNext(response);
responseObserver.onCompleted();
shutdownManagedChannel(channel);
Exception:
Feb 04, 2021 11:33:50 PM io.grpc.internal.SerializingExecutor run
SEVERE: Exception while executing runnable io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1HalfClosed@7fbc2a7f
java.lang.IllegalArgumentException: Invalid DNS name: linkview_domain_metadata:9000
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:217)
at io.grpc.internal.DnsNameResolver.<init>(DnsNameResolver.java:171)
at io.grpc.internal.DnsNameResolverProvider.newNameResolver(DnsNameResolverProvider.java:58)
at io.grpc.internal.DnsNameResolverProvider.newNameResolver(DnsNameResolverProvider.java:41)
at io.grpc.NameResolverRegistry$NameResolverFactory.newNameResolver(NameResolverRegistry.java:154)
.......
Dockerfile:
FROM java:8
WORKDIR /
ADD /target/metadata-1.0-jar-with-dependencies.jar metadata-1.0.jar
EXPOSE 9000
CMD java -jar metadata-1.0.jar
Docker command:
docker run --network-alias metadata --network backend -d metadata
question from:
https://stackoverflow.com/questions/66056127/inter-container-docker-communication-using-network-alias-results-in-invalid-dns 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…