-
-
Save remy-actual/ab0bf373d953bb04065a to your computer and use it in GitHub Desktop.
Deploying Go Web Apps With Docker source files -- https://medium.com/@shijuvar/deploying-go-web-apps-with-docker-1b7561b36f53
This file contains hidden or 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
| # golang image where workspace (GOPATH) configured at /go. | |
| FROM golang:latest | |
| # Copy the local package files to the container’s workspace. | |
| ADD . /go/src/github.com/shijuvar/golang-docker | |
| # Build the golang-docker command inside the container. | |
| RUN go install github.com/shijuvar/golang-docker | |
| # Run the golang-docker command when the container starts. | |
| ENTRYPOINT /go/bin/golang-docker | |
| # http server listens on port 8080. | |
| EXPOSE 8080 |
This file contains hidden or 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" | |
| "io" | |
| "log" | |
| "net/http" | |
| ) | |
| func helloHandler(res http.ResponseWriter, req *http.Request) { | |
| res.Header().Set( | |
| "Content-Type", | |
| "text/html", | |
| ) | |
| io.WriteString( | |
| res, | |
| `<doctype html> | |
| <html> | |
| <head> | |
| <title>Hello Gopher</title> | |
| </head> | |
| <body> | |
| Hello Gopher </br> | |
| It is really awesome that both Docker and Kubernetes are written in Go! | |
| </body> | |
| </html>`, | |
| ) | |
| } | |
| func defaultHandler(w http.ResponseWriter, r *http.Request) { | |
| fmt.Fprintf(w, "Go web app powered by Docker") | |
| } | |
| func main() { | |
| http.HandleFunc("/", defaultHandler) | |
| http.HandleFunc("/hello", helloHandler) | |
| err := http.ListenAndServe(":8080", nil) | |
| if err != nil { | |
| log.Fatal("ListenAndServe: ", err) | |
| return | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment