3

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",
}
...
Amjed saleel
  • 348
  • 1
  • 3
  • 15
  • Is the go program running on port 8007? your port 7000 will connect to port 8007 in the container but if the go app isn't running or not listening on that port, you won't connect to anything. ideas: * the program crashed * the program never started up (entrypoint?) * the program is listening on a different port or not at all – PotatoesFall Jul 08 '22 at 11:06
  • @PotatoesFall program is running the port 8007. – Amjed saleel Jul 08 '22 at 11:19

1 Answers1

3

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",
}
davidriod
  • 937
  • 5
  • 14