Skip to content

Instantly share code, notes, and snippets.

@r6m
Created January 8, 2018 21:38
Show Gist options
  • Save r6m/0f5c11bd709a8acd606bd59420bf1e52 to your computer and use it in GitHub Desktop.
Save r6m/0f5c11bd709a8acd606bd59420bf1e52 to your computer and use it in GitHub Desktop.
golang multi stage docker build
## builder docker
FROM golang:1.9.2 as builder
WORKDIR /go/src/buddytest
copy ./ .
RUN curl https://glide.sh/get | sh
RUN glide install
RUN go test
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o app .
## final docker
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /app
# notice [--from]: here we get app file from previous docker build stage
COPY --from=builder /go/src/buddytest/app .
CMD ["./app"]
@r6m
Copy link
Author

r6m commented Jan 8, 2018

pipe docker builds for less size images

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