Created
February 6, 2018 19:19
-
-
Save som-poddar/85353b174e70780001330384f090694b to your computer and use it in GitHub Desktop.
Docker Go Sample
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" | |
"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") | |
} | |
} |
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.8.6-alpine3.5 | |
WORKDIR /app | |
ADD go-docker /app/ | |
ENTRYPOINT ["./go-docker"] |
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
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