Created
February 18, 2020 19:23
-
-
Save micahyoung/5193b8a7acbbc26ed8bb3c2e47591a5a to your computer and use it in GitHub Desktop.
Debugging Windows 10 Docker not exposing ports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Working | |
Microsoft Windows [Version 10.0.18362.592] | |
Docker 2.1.04 | |
docker build -t webserver . | |
docker run -p8080:8080 webserver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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