Skip to content

Instantly share code, notes, and snippets.

@PatrickKalkman
Created February 7, 2021 19:48
Show Gist options
  • Select an option

  • Save PatrickKalkman/b7fabb5dfea9f09200c2e34aa792bd6b to your computer and use it in GitHub Desktop.

Select an option

Save PatrickKalkman/b7fabb5dfea9f09200c2e34aa792bd6b to your computer and use it in GitHub Desktop.
Add non root user to docker file
FROM python:3.8.7-alpine
RUN pip install --upgrade pip
RUN pip install pipenv
RUN adduser -D python
# Create the work dir and set permissions as WORKDIR set the permissions as root
RUN mkdir /home/python/app/ && chown -R python:python /home/python/app
WORKDIR /home/python/app
USER python
RUN pip install --user pipenv
ENV PATH="/home/worker/.local/bin:${PATH}"
COPY --chown=python:python Pipfile Pipfile
RUN pipenv lock -r > requirements.txt
RUN pip install --user -r requirements.txt
COPY --chown=python:python . .
CMD ["python", "main.py"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment