« Back to Index

Building a Go program via Docker

View original Gist on GitHub

building-a-go-program-via-docker.sh

docker run -\
  -rm=true \
  -v $WORKSPACE/src:/gopath/src/github.com/foo/bar/src \
  -v $WORKSPACE/src:/app \
  -e "GOPATH=/gopath" \
  -w /app golang:1.5 sh \
  -c 'CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags=\"-s\" -o bar'
  
# Refactor:
# Set the working directory to `/gopath/src/github.com/foo/bar/src
# Which means you don't need the second volume mount to /app

docker run \
  -v "$PWD":/go/src/github.com/integralist/go-requester \
  -w /go/src/github.com/integralist/go-requester \
  -p 8080:8080 \
  golang:latest go run requester.go