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",
}
...
CodePudding user response:
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",
}