我想尝试从主机上的docker容器内运行GRPC服务器。我想通过在" host"中运行它来看看我是否可以获得更好的性能。网络模式。我是从java开始的
CreateContainerResponse container = dockerClient.createContainerCmd("darthshana/lostvictoryserver:0.0.1-SNAPSHOT")
.withVolumes(volume1)
.withBinds(new Bind("/home/darthshana/gameEngine/lostVictoriesServer.properties", volume1))
.withExposedPorts(tcp5055)
.withPortBindings(portBindings)
.withNetworkMode("host")
.withEnv("GAME_NAME="+gameName, "GAME_PORT=5055")
.exec();
导致以下docker容器启动
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b982b240ada2 darthshana/lostvictoryserver:0.0.1-SNAPSHOT "/usr/bin/java -ja..." About a minute ago Up About a minute angry_curie
在主机上我可以看到它暴露了正确的端口
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::5055 :::* LISTEN -
我在主机上有防火墙规则
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:5055 state NEW
允许我从外面连接到GRPC服务器..一切都很棒! 然而.... 由于某种原因,我无法从同一主机内部连接到grpc服务器..我试图从主机本身运行的另一个java进程(不是一个docker容器)做的...我试过了
ManagedChannel managedChannel = ManagedChannelBuilder.forAddress("......", game.getPort())
.usePlaintext(true)
.build();
在" ......"字符串localhost,127.0.0.1以及我从主机外部成功使用的服务器的外部IP ..但它们都不起作用,GRPC调用已经完成,但它永远不会到达grpc服务器而且不会返回。我没有收到任何错误。但是,如果我杀死docker容器,我会收到错误
2017-10-12 19:03:29.484 ERROR 3366 --- [io-8080-exec-10] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is io.grpc.StatusRuntimeException: INTERNAL: Connection closed with unknown cause] with root cause
io.grpc.StatusRuntimeException: INTERNAL: Connection closed with unknown cause
at
io.grpc.stub.ClientCalls.toStatusRuntimeException
(ClientCalls.java:210) ~[grpc-stub-1.6.1.jar!/:1.6.1]
它就像连接成功但呼叫没有通过。 我已尝试从主机外部到在docker内运行的同一个grpc服务器完全相同的调用,它运行正常。
为什么我无法从本地主机连接到它?任何指导将不胜感激