Created
August 27, 2024 20:22
-
-
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.
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
# 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