Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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",
}
...
like image 769
Amjed saleel Avatar asked Oct 17 '25 17:10

Amjed saleel


1 Answers

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",
}
like image 75
davidriod Avatar answered Oct 20 '25 09:10

davidriod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!