2

I did read the answer to [this similar question][1] but it didn't help to resolve the issue for me.

My setup:

  • a remote gRPC service;
  • a .py client that runs directly on the host.

In that configuration everything works fine. However, if I start that remote gRPC service in local Docker container (.py client still runs locally):

08:49:00.434005     7 server.cc:53] Server starting
08:49:00.435603     7 server.cc:59] Server listening on 0.0.0.0:9000

The command I use to run a gRPC service: sudo docker run --rm -it -u dud --net=host --entrypoint=/usr/local/bin/application COOL_APP

Here's a snippet of code of my .py client:

HOST = 'localhost'
PORT = '9000'
with grpc.insecure_channel('{}:{}'.format(HOST, PORT)) as channel:

I receive the following error (AFAIK it means my .py client couldn't connect to the host:port of my Docker service):

Traceback (most recent call last):
  File "client.py", line 31, in <module>
    for record in reader:
  File "/usr/local/lib/python2.7/site-packages/grpc/_channel.py", line 367, in next
    return self._next()
  File "/usr/local/lib/python2.7/site-packages/grpc/_channel.py", line 358, in _next
    raise self
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
    status = StatusCode.UNAVAILABLE
    details = "Connect Failed"
    debug_error_string = "{"created":"@1550567018.554830000","description":"Failed to create subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":2261,"referenced_errors":[{"created":"@1550567018.554828000","description":"Pick Cancelled","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":245,"referenced_errors":[{"created":"@1550567018.554798000","description":"Connect Failed","file":"src/core/ext/filters/client_channel/subchannel.cc","file_line":867,"grpc_status":14,"referenced_errors":[{"created":"@1550567018.554789000","description":"Failed to connect to remote host: OS Error","errno":61,"file":"src/core/lib/iomgr/tcp_client_posix.cc","file_line":207,"os_error":"Connection refused","syscall":"connect","target_address":"ipv6:[::1]:9000"}]}]}]}"

I've tried setting both localhost:9000, 0.0.0.0:9000, and :9000 in my .py client and it didn't work.

I'm not sure whether it makes sense, but when I run:

user-dev:~ user$ lsof -i tcp:8080
COMMAND     PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
myservice 53941 user    6u  IPv4 0x40c50fcf1d04701d      0t0  TCP localhost:http-alt (LISTEN)
user-dev:~ user$ lsof -i tcp:9000

I.e., my terminal doesn't show anything for tcp:9000 (I run the command above to check whether something actually listens to localhost:9000).

Update: when I run a hello-world [container][2] with -p 9000:9000 I receive a different error:

debug_error_string = "{"created":"@1550580085.678869000","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1036,"grpc_message":"Socket closed","grpc_status":14}"
``` so I assume something is wrong with my gRPC service image / Docker flags.


  [1]: https://stackoverflow.com/questions/43911793/cannot-connect-to-go-grpc-server-running-in-local-docker-container
  [2]: https://github.com/crccheck/docker-hello-world
H. Desane
  • 593
  • 1
  • 8
  • 16

3 Answers3

1

You need to tell docker to expose the port externally.

Try adding -p 9000:9000 to your docker run command.

Frax
  • 3,075
  • 1
  • 23
  • 27
  • 1
    It totally makes sense, but doesn't work: I tried `localhost:9000`, `0.0.0.0:9000`, and `:9000` as `host:port`, and the error stays the same. – H. Desane Feb 19 '19 at 09:48
1

The right command was:

docker run -p 9000:9000 -it -u dud --entrypoint=/usr/local/bin/application COOL_APP

Basically used -p 9000:9000 and removed --net=host.

H. Desane
  • 593
  • 1
  • 8
  • 16
0

Your host ip is not localhost but it is docker's ip address. You can find docker ip by "docker network inspect bridge | grep IPv4Address"