c# Grpc Client Not able to connect to Grpc Server hosted in docker(for windows) container on localhost c# Grpc Client Not able to connect to Grpc Server hosted in docker(for windows) container on localhost docker docker

c# Grpc Client Not able to connect to Grpc Server hosted in docker(for windows) container on localhost


(1) Do not use localhost in your GRPC server inside docker, it will not work as the loopback localhost cannot be reached from outside docker, you need to listen on all interfaces, so use "0.0.0.0", eg.

Ports = {new ServerPort("0.0.0.0", port, ServerCredentials.Insecure)}

Here is a stack that refers to this issue: Cannot connect to Go GRPC server running in local Docker container

(2) I had this same issue. I found that the issue was the I was not using an interactive shell when using docker run or docker compose. If you are using docker run then you need to use the -it commands, and for docker compose you need to use stdin_open: true and tty:true.

Docker run example

docker run --name grpcserver -p 8081:8081 -it -d grpcserver

Docker compose example

version: '3'services:  web:    container_name: mynginx    build:      context: ./nginx      dockerfile: Dockerfile    ports:      - 8080:80  grpcserver:    image: grpcserver    container_name: grpcserver    stdin_open: true    tty: true    build:      context: .      dockerfile: Dockerfile

Here is another stack that talks about this:Interactive shell using Docker Compose

Good luck!


I came across the same issue. But finally it is related with proxy configuration. GRPC uses "HTTP_PROXY" and "HTTPS_PROXY" environment configuration. Unfortunately my grpc server running on local network which does not require a proxy. I missed to define the "NO_PROXY" environment variable.

Once I added the grpc server ip into the NO_PROXY, it started working.

Note:

  1. I am able to get docker working with just "localhost". I have not bounded my grpc server to "0.0.0.0"
  2. I diagnosed the problem by enabling the GRPC tracing logging. After enabled the tracing you have to use the following code to show the logs into the console.

ref: https://github.com/grpc/grpc/blob/master/TROUBLESHOOTING.md

GrpcEnvironment.SetLogger(new ConsoleLogger());