Created
May 10, 2021 08:14
-
-
Save lifeofguenter/d28d8adc8ce61e63bf2ebc79367c2993 to your computer and use it in GitHub Desktop.
Multistep Docker build with Golang
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
# builder | |
FROM golang:1.16-buster AS builder | |
ARG DEBIAN_FRONTEND="noninteractive" | |
RUN set -ex && \ | |
apt-get -qq update && apt-get -y -qq install \ | |
gcc | |
WORKDIR /go/src/app | |
COPY go.* ./ | |
RUN go mod download | |
COPY . . | |
RUN go get -d -v | |
RUN GOOS=linux GOARCH=amd64 go build -a -v | |
# main | |
FROM debian:buster-slim | |
ARG DEBIAN_FRONTEND="noninteractive" | |
EXPOSE 8080 | |
ENTRYPOINT ["my-app"] | |
RUN set -ex &&\ | |
apt-get -qq update && apt-get -y -qq install \ | |
bash \ | |
ca-certificates && \ | |
useradd -md /app -s /bin/bash app | |
USER app | |
WORKDIR /app | |
COPY --from=builder --chown=app:app /go/src/app/my-app /usr/local/bin/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment