Home > Backend Development > Golang > Why Does My Docker Container Throw 'Recv failure: Connection reset by peer' When Accessing Its Mapped Port?

Why Does My Docker Container Throw 'Recv failure: Connection reset by peer' When Accessing Its Mapped Port?

Patricia Arquette
Release: 2024-12-02 10:54:12
Original
127 people have browsed it

Why Does My Docker Container Throw

Docker Port Exposing Issue: Understanding "Recv failure: Connection reset by peer" Error

When attempting to run a Go app binary within a Docker container and access it via its mapped port, you may encounter the "Recv failure: Connection reset by peer" error. This indicates an issue with the port mapping or the application's internal configuration.

The issue arises when the application specifies an IP address like "localhost:8081" for its gRPC listening endpoint. When running within a container, this setup only allows connections from within the container itself.

Solution: Use Host-wide Listening

To resolve this issue, you should configure your application to bind to all available host interfaces, instead of "localhost". This can be achieved by simply omitting the IP address in your listening call:

http.ListenAndServe(":8081", nil)
Copy after login

By doing this, the application starts listening on all interfaces with port 8081, allowing connections from both within and outside the container. This resolves the issue and enables external access to your gRPC endpoint.

The above is the detailed content of Why Does My Docker Container Throw 'Recv failure: Connection reset by peer' When Accessing Its Mapped Port?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template