Sunday, July 10, 2022

[SOLVED] curl: (56) Recv failure: Connection reset by peer in golang with docker

Issue

I am dockerized a golang application and i am trying to access the application. Application running in port 8007

I am running the container the following command

docker run --name sample_go_app -p 7000:8007 sample_go

After tried curl http://localhost:7000 but getting error

curl: (56) Recv failure: Connection reset by peer

main.go

...
srv := &http.Server {
Handler: router,
Addr:    "localhost:8007",
}
...

Solution

You're binding the socket to localhost address which cannot be reached from outside of your container. You should only add the port part in the address so that your process accepts connection from any network interface. You can define your server this way:

srv := &http.Server {
Handler: router,
Addr:    ":8007",
}


Answered By - davidriod
Answer Checked By - David Marino (WPSolving Volunteer)