"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Does My Go App Get "Recv failure: Connection reset by peer" When Running in a Docker Container?

Why Does My Go App Get "Recv failure: Connection reset by peer" When Running in a Docker Container?

Published on 2024-12-23
Browse:856

Why Does My Go App Get

Docker Port Exposure Issue: Resolving "Recv failure: Connection reset by peer"

Upon attempting to run a Go app binary within a Docker container, users may encounter an issue where the app fails to receive external connections. This error manifests itself as "Recv failure: Connection reset by peer" when invoking curl commands.

The source of this problem lies in the network configuration of the container. When the app is executed within the container, the following command is typically used:

http.ListenAndServe("localhost:8081", nil)

However, this configuration only allows connections to be established from within the container itself. To resolve this issue and enable external access to the app, the command should be modified to:

http.ListenAndServe(":8081", nil)

By omitting the "localhost" prefix, the app opens itself to connections originating from both within and outside the container. This modification allows for proper external communication with the app when it is run in a Docker environment.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3