Skip to content

Instantly share code, notes, and snippets.

@som-poddar
Created February 6, 2018 19:19
Show Gist options
  • Save som-poddar/85353b174e70780001330384f090694b to your computer and use it in GitHub Desktop.
Save som-poddar/85353b174e70780001330384f090694b to your computer and use it in GitHub Desktop.
Docker Go Sample
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/gorilla/mux"
)
func main() {
r := mux.NewRouter()
r.HandleFunc("/", Hello)
http.Handle("/", r)
fmt.Println("Starting up on 8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
func Hello(w http.ResponseWriter, req *http.Request) {
if value, ok := os.LookupEnv("ENV"); ok {
fmt.Fprintln(w, "Hello World, in ", value)
} else {
fmt.Fprintln(w, "Hello world! in, ", "development")
}
}
FROM golang:1.8.6-alpine3.5
WORKDIR /app
ADD go-docker /app/
ENTRYPOINT ["./go-docker"]
build:
go get github.com/gorilla/mux
go build -o go-docker
pack:
docker build --no-cache -t ellation/docker-app .
run:
docker run --rm -p 8080:8080 ellation/docker-app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment