FROM python:3.9-slim # 1. Install system dependencies required by OpenCV (must be run as root) RUN apt-get update && apt-get install -y \ libgl1 \ libglib2.0-0 \ libsm6 \ libxrender1 \ libxext6 \ libxcb1 \ && rm -rf /var/lib/apt/lists/* # 2. Set up the non-root user (Required by Hugging Face) RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" # 3. Set the working directory WORKDIR /app # 4. Copy requirements and install dependencies COPY --chown=user ./requirements.txt requirements.txt RUN pip install --no-cache-dir --upgrade -r requirements.txt # 5. Copy the rest of your application code COPY --chown=user . /app # 6. Start the FastAPI server CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]