Skip to content

Commit 86c6cf7

Browse files
committed
build(Dockerfile): use a non-root user for building image
1 parent 8d73671 commit 86c6cf7

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
FROM python:3.13-slim
22

3+
# Create a non-root user and group
4+
RUN groupadd -r appgroup && useradd -r -m -g appgroup appuser
5+
36
# Set working dir as /app inside the container
47
WORKDIR /app
58

69
# Copy the rates/requirements.txt.lock to the container
710
COPY ./rates/requirements.txt.lock /app
811

12+
# Install dependencies as root
913
RUN pip install --no-cache-dir gunicorn==21.2.0 && \
1014
pip install --no-cache-dir -r requirements.txt.lock
1115

1216
# Copy the application code
1317
COPY ./rates /app
1418

19+
# Set the correct ownership of the /app folder to the appuser
20+
RUN chown -R appuser:appgroup /app
21+
22+
# Switch to the non-root user for security
23+
USER appuser
24+
1525
# Make port 3000 available to the world outside this container
1626
EXPOSE 3000
1727

1828
# Define environment variables
1929
ENV PYTHONUNBUFFERED 1
2030

21-
# Run Gunicorn with your application
31+
# Run Gunicorn with your application as appuser
2232
CMD gunicorn -b :3000 wsgi

0 commit comments

Comments
 (0)