3

我稍微修改了这个例子:https ://github.com/grpc/grpc-web/tree/master/net/grpc/gateway/examples/echo 。我在暴露端口 8080 的 docker 容器上运行特使(需要运行此代理服务器,因为浏览器无法直接与后端 gRPC 服务对话)。我在我的本地主机(特使 docker 容器的主机)上运行所有服务。但是,我似乎无法将 docker 容器中的特使连接到主机上运行的服务。

grpc_cli我在容器中编译,当我运行时grpc_cli ls 192.168.1.10:9000(主机的 LAN IP 地址和运行服务的端口),我得到

root@bdc9ac396a87:~/grpc# ./bins/opt/grpc_cli ls 192.168.1.10:9000
Received an error when querying services endpoint.
ServerReflectionInfo rpc failed. Error code: 14, message: failed to connect to all addresses, debug info: {"created":"@1569023274.866465052","description":"Failed to pick subchannel","file"
:"src/core/ext/filters/client_channel/client_channel.cc","file_line":3876,"referenced_errors":[{"created":"@1569023274.866463178","description":"failed to connect to all addresses","file":"
src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":395,"grpc_status":14}]}

当我使用 docker0 接口的 IP 地址时,我得到一个几乎相同的错误,它也应该提供到主机的连接。

root@bdc9ac396a87:~/grpc# ./bins/opt/grpc_cli ls 172.17.0.1:9000                                                                                                                             
Received an error when querying services endpoint.                                                                                                                                           
ServerReflectionInfo rpc failed. Error code: 14, message: failed to connect to all addresses, debug info: {"created":"@1569022455.801913949","description":"Failed to pick subchannel","file"
:"src/core/ext/filters/client_channel/client_channel.cc","file_line":3876,"referenced_errors":[{"created":"@1569022455.801910006","description":"failed to connect to all addresses","file":"
src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":395,"grpc_status":14}]}

但是,从主机运行一个简单的 http 服务器, python -m http.server 我可以从容器中运行以下命令:

wget 172.17.0.1:8000/test.txt // works
wget 192.168.1.10:8000/test.txt // works

主机上的客户端(不在容器中)连接并与服务正常工作,因此这不是服务器问题。

docker 会阻止某些类型的流量吗?我注意到在示例中服务器被放置在另一个 docker 容器上,并且它可以工作(它也可以在我本地工作),但我更希望在构建和测试它们时让我的服务在我的主机上运行。是否有设置可以从容器启用 gRPC 到主机上的服务?

Docker 版本 1.13.1,构建 47e2230/1.13.1 Fedora 29

4

0 回答 0