| # Use Python 3.9 as the base image | |
| FROM python:3.9 | |
| # Create a user with ID 1000 | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV PATH="/home/user/.local/bin:$PATH" | |
| # Set the working directory | |
| WORKDIR /app | |
| # Copy the requirements.txt file and install dependencies | |
| COPY --chown=user ./requirements.txt requirements.txt | |
| RUN pip install --no-cache-dir --upgrade -r requirements.txt | |
| # Install system dependencies needed for OpenCV and other libraries | |
| USER root | |
| RUN apt-get update && apt-get install -y \ | |
| libgl1-mesa-glx \ | |
| libglib2.0-0 \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Return to the user 'user' for safety | |
| USER user | |
| # Copy the entire app directory to the container | |
| COPY --chown=user . /app | |
| # Set the command to run the app with Gunicorn | |
| CMD ["gunicorn", "-b", "0.0.0.0:7860", "app:app"] | |