Spaces:
Sleeping
Sleeping
File size: 1,869 Bytes
b70573c 3619778 99d7bc3 f008752 4e563f3 99d7bc3 c036dc7 4e563f3 99d7bc3 255d73a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# Use the official Python 3.9 slim image as the base
FROM python:3.9-slim
# --- Permission Fix Section ---
# Create a non-root user and group with a specific UID/GID
# Using UID/GID 1000 is common, but ensure it aligns with your host if mounting volumes extensively.
RUN groupadd --gid 1000 appgroup && \
useradd --uid 1000 --gid 1000 --create-home --shell /bin/bash appuser
# Set environment variables for the new user's home directory
# This makes paths more robust and follows conventions
ENV HOME=/home/appuser
ENV APP_HOME=/home/appuser/app
# Ensure the app's virtual environment (if any future deps need it) or local bins are in PATH
ENV PATH=${HOME}/.local/bin:$PATH
# Create the application directory within the user's home
RUN mkdir -p ${APP_HOME}
# Set the working directory to the new app directory
WORKDIR ${APP_HOME}
# --- Dependency Installation ---
# Copy and install Python requirements
COPY ./requirements.txt ${APP_HOME}/requirements.txt
RUN pip install --no-cache-dir -r ${APP_HOME}/requirements.txt
# --- Application Code Copy ---
# Copy application code, ensuring ownership by the appuser
# Use --chown to set ownership during the copy step itself
COPY --chown=appuser:appgroup . ${APP_HOME}
# --- Final Ownership and User Switch ---
# Explicitly change ownership of the entire app directory again.
# This catches any files created during build steps or ensures consistency.
RUN chown -R appuser:appgroup ${APP_HOME}
# Switch to the non-root user for running the application
# This is the crucial step to ensure the process has the right permissions
USER appuser
# --- Expose and Run ---
# Expose the port the app runs on
EXPOSE 7860
# Define the command to run the application using Gunicorn
# Ensure it binds to 0.0.0.0 to be accessible outside the container
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "120", "app:app"] |