Skip to content

Instantly share code, notes, and snippets.

@mustafaturan
Last active September 4, 2019 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustafaturan/7c477126ee7ad3f54b5de5b68b7ec384 to your computer and use it in GitHub Desktop.
Save mustafaturan/7c477126ee7ad3f54b5de5b68b7ec384 to your computer and use it in GitHub Desktop.
Go - Dockerfile - 9.22MB
FROM golang:1.13 as build
WORKDIR /app
COPY go.mod go.sum ./
RUN GO111MODULE=on go mod download
COPY . .
RUN CGO_ENABLED=0 go build -v
# Create a "nobody" non-root user for the next image by crafting an /etc/passwd
# file that the next image can copy in. This is necessary since the next image
# is based on scratch, which doesn't have adduser, cat, echo, or even sh.
RUN echo "nobody:x:65534:65534:Nobody:/:" > /etc_passwd
# No need extra files
FROM scratch
ENV PORT=3000
COPY --from=build /etc/ssl/certs/ /etc/ssl/certs/
COPY --from=build /app/<myawesomeappname> /
COPY --from=build /etc_passwd /etc/passwd
USER nobody
CMD ["/<myawesomeappname>"]
# Replace <myawesomeappname> with your app name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment