Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run container as non-root user #991

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ RUN set ex \
&& rm -rf /var/lib/apt/lists/* \
&& chmod +x /usr/bin/tini

COPY . .
# Group 'python' (GID 999) and user 'python' (uid 999) are created
RUN groupadd -g 999 python && useradd -u 999 -r -g python python

# App folder and '/nginx' mount point are created with the new user as owner
RUN mkdir -p /nginx && chown -R python:python /nginx .
hectorgomezv marked this conversation as resolved.
Show resolved Hide resolved
COPY --chown=python:python . .

# Container is ran by the new user
# UID:GID is used as Kubernetes requires numeric IDs: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#securitycontext-v1-core
USER 999:999
fmrsabino marked this conversation as resolved.
Show resolved Hide resolved

RUN DEFAULT_FILE_STORAGE=django.core.files.storage.FileSystemStorage python src/manage.py collectstatic --noinput
ENTRYPOINT ["/usr/bin/tini", "--", "./docker-entrypoint.sh"]