From 9fb88178790e7ec1ab46afb0e26df7acbaa4b692 Mon Sep 17 00:00:00 2001 From: Hezi Aharon Date: Sat, 2 Nov 2024 06:41:57 +0000 Subject: [PATCH] Update Dockerfile --- Dockerfile | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2b16513..5c56d19 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,23 @@ # Use a slim base image to reduce potential vulnerabilities FROM python:3.10-slim-bookworm -# Create a non-root user and group -RUN groupadd -r appuser && useradd --no-log-init -r -g appuser appuser +# Create a non-root user and group with home directory set to /usr/src/app +RUN useradd --no-log-init -r -m -d /usr/src/app appuser # Set the working directory WORKDIR /usr/src/app -# Copy the requirements file and install the dependencies -COPY --chown=appuser:appuser requirements.txt . +# Copy the requirements file and install the dependencies as root +COPY requirements.txt . -# Install uv and the dependencies without caching to reduce image size RUN pip install --no-cache-dir uv==0.4.28 && \ pip install --no-cache-dir -r requirements.txt -# Copy the application code with appropriate ownership -COPY --chown=appuser:appuser . . +# Copy the application code and set ownership to appuser +COPY . . -# Adjust permissions of the application directory -RUN chmod -R u+rwX,go-rwx /usr/src/app - -# Ensure parent directories are accessible -RUN chmod o+rx /usr /usr/src +# Change ownership of the application directory to appuser +RUN chown -R appuser:appuser /usr/src/app # Switch to the non-root user USER appuser