Home >Backend Development >Golang >Why Does My gRPC Client Fail to Connect to a Go Server in a Docker Container?
Connecting to Go GRPC Server Running in Local Docker Container
Problem:
When attempting to connect a gRPC client to a Go gRPC server running within a Docker container, an error is encountered:
transport: http2Client.notifyError got notified that the client transport was broken EOF. FATA[0000] rpc error: code = Internal desc = transport is closing
Solution:
The issue arises when the gRPC server is configured to listen on a specific hostname or IP address, such as localhost. Within Docker, the localhost address refers only to loopback connections originating from within the container itself.
To resolve this issue, the server should be configured to listen on all available IP addresses of the container. This can be achieved by changing the listen endpoint from:
endpoint := "localhost:51672"
to:
endpoint := ":51672"
By using ":" as the listen address, the server will bind to all interfaces and IP addresses within the container, allowing external connections to be forwarded and established.
Additional Information:
The above is the detailed content of Why Does My gRPC Client Fail to Connect to a Go Server in a Docker Container?. For more information, please follow other related articles on the PHP Chinese website!