Skip to content

Instantly share code, notes, and snippets.

@AlperRehaYAZGAN
Created February 12, 2023 23:29
Show Gist options
  • Save AlperRehaYAZGAN/442c1b91c1e0b465294d8756306e0984 to your computer and use it in GitHub Desktop.
Save AlperRehaYAZGAN/442c1b91c1e0b465294d8756306e0984 to your computer and use it in GitHub Desktop.
Golang simple multistage dockerfile with non-root user.
# 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