Skip to content

Instantly share code, notes, and snippets.

@Igosuki
Last active August 29, 2015 14:26
Show Gist options
  • Save Igosuki/aec64c94b6889b7d97b5 to your computer and use it in GitHub Desktop.
Save Igosuki/aec64c94b6889b7d97b5 to your computer and use it in GitHub Desktop.
Tiny docker image and go runtime
  1. Vendor
go get github.com/gorilla/mux
godep save -r
  1. Build binary
docker run --rm -it -v "$GOPATH":/gopath -v "$(pwd)":/app -e "GOPATH=/gopath" -w /app golang:1.4.2 sh -c 'CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o hello'
  1. Build docker image
docker build -t treeder/go-hello-http .
  1. Run it
docker run --rm -it -p 8080:8080 treeder/go-hello-http
FROM centurylink/ca-certs
MAINTAINER Travis Reeder "[email protected]"
EXPOSE 8080
WORKDIR /app
# copy binary into image
COPY hello /app/
ENTRYPOINT ["./hello"]
package main
import (
"fmt"
"log"
"net/http"
"github.com/treeder/easy-go-in-docker/Godeps/_workspace/src/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) {
fmt.Fprintln(w, "Hello world!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment