Skip to content

Instantly share code, notes, and snippets.

@PaluMacil
Created August 9, 2017 21:24
Show Gist options
  • Save PaluMacil/8f5d0ef6f45a9ba7a5288b8c63583cab to your computer and use it in GitHub Desktop.
Save PaluMacil/8f5d0ef6f45a9ba7a5288b8c63583cab to your computer and use it in GitHub Desktop.
Multi-stage Dockerfile for building a ~10 MB Go container
FROM golang:1.8.3 as goget
LABEL maintainer="dcwolf@gmail.com"
ADD ./main.go /go/src/github.com/palumacil/example/main.go
ADD ./handler.go /go/src/github.com/palumacil/example/handler.go
ADD ./config.go /go/src/github.com/palumacil/example/config.go
RUN go get .\..
FROM golang:1.8.3-alpine as gobuild
LABEL maintainer="dcwolf@gmail.com"
COPY --from=goget /go/src /go/src
RUN go install github.com/palumacil/example
FROM alpine
LABEL maintainer="dcwolf@gmail.com"
COPY --from=gobuild /go/bin /go/bin
EXPOSE 80
CMD /go/bin/example -port=80 -secrets=/run/secrets/example.json -log=/logs/example.log
@PaluMacil
Copy link
Author

$projectPath = (Get-Item -Path "." -Verbose).FullName
$secrets = "$env:USERPROFILE\secrets:/run/secrets"

docker rm -f example
docker rmi -f example:test
docker build -t example:test .
docker run -d -v "$projectPath/logs:/logs" -v "$secrets" -p 8119:80 --name example example:test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment