I am building a simple API with go and I am trying to deploy with docker. The process builds, and when I run (from docker) the app starts.
But when I try to access endpoints with curl, I get this error (curl: (56) Recv failure: Connection reset by peer).
I have this snippet in my main function:
port := os.Getenv(“PORT”) if port == “” { port = “2000” }
and I then bind to listen and serve:
Like so:
err := http.ListenAndServe(":"+port, nil) if err != nil { //log.Fatal(“Server error”, err) }
I am not sure the error is coming from here, but I have tried to remove that first bit of code and leave the port empty, still makes no difference.
The API works without docker (with those snippets) but would not work if I try to run with docker.
ok, good… but where is code IN the container listening on port 8080?
cause the code says use port 2000 in the container
port := os.Getenv(“PORT”) if port == “” { port = “2000” }
and I then bind to listen and serve:
Like so:
err := http.ListenAndServe(":"+port, nil) if err != nil { //log.Fatal(“Server error”, err)