Skip to content

Instantly share code, notes, and snippets.

@micahyoung
Created February 18, 2020 19:23
Show Gist options
  • Save micahyoung/5193b8a7acbbc26ed8bb3c2e47591a5a to your computer and use it in GitHub Desktop.
Save micahyoung/5193b8a7acbbc26ed8bb3c2e47591a5a to your computer and use it in GitHub Desktop.
Debugging Windows 10 Docker not exposing ports
FROM golang:1.13-nanoserver-1809
COPY main.go c:/main.go
RUN go build -o c:\\webserver.exe c:\\main.go
CMD ["c:\\webserver.exe"]
Working
Microsoft Windows [Version 10.0.18362.592]
Docker 2.1.04
docker build -t webserver .
docker run -p8080:8080 webserver
package main
import (
"fmt"
"net/http"
"os"
"strconv"
)
const DEFAULT_PORT = 8080
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there %s!", r.URL.Path[1:])
}
func main() {
var port int = DEFAULT_PORT
var err error
sport := os.Getenv("PORT")
if sport != "" {
port, err = strconv.Atoi(sport)
if err != nil {
panic(err)
}
}
fmt.Printf("Running on :%d", port)
http.HandleFunc("/", handler)
http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment