Skip to content

Instantly share code, notes, and snippets.

@remy-actual
Forked from shijuvar/main.go
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save remy-actual/ab0bf373d953bb04065a to your computer and use it in GitHub Desktop.

Select an option

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
# 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
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