Skip to content

Instantly share code, notes, and snippets.

@BretFisher
Created August 27, 2024 20:22
Show Gist options
  • Save BretFisher/04c5e682d8919126691fe122ae6742d7 to your computer and use it in GitHub Desktop.
Save BretFisher/04c5e682d8919126691fe122ae6742d7 to your computer and use it in GitHub Desktop.
Adding a non-root user to an Alpine Docker image. This example uses the python image, but it works the same in other Alpine images.
# syntax=docker/dockerfile:1
FROM python:alpine
# create the group and user
RUN addgroup -g 1000 python \
&& adduser -u 1000 -G python -D python
# stating USER before WORKDIR means the directory is created with the non-root proper ownership
USER python
WORKDIR /app
# make sure to chown files you COPY or ADD in
COPY --chown=python:python . .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment