Created
February 12, 2023 23:29
-
-
Save AlperRehaYAZGAN/442c1b91c1e0b465294d8756306e0984 to your computer and use it in GitHub Desktop.
Golang simple multistage dockerfile with non-root user.
This file contains hidden or 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
# build stage | |
FROM golang:1.17-alpine3.15 AS build-env | |
RUN apk add build-base | |
ADD . /src | |
RUN cd /src && go build -o main | |
# final stage | |
FROM alpine | |
WORKDIR /app | |
COPY --from=build-env /src/main /app/ | |
# create user and give it permission | |
RUN addgroup -S appgroup && adduser -S appuser -G appgroup | |
RUN chown -R appuser:appgroup /app | |
USER appuser | |
ENTRYPOINT ./main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment