docker容器中的gRPC无法连接到主机上的服务

时间:2019-09-21 00:10:03

标签: docker networking grpc grpc-web

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

我在容器中编译了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

0 个答案:

没有答案