FROM python:3.9 # 1. Create a non-root user RUN useradd -m -u 1000 user USER user # 2. Set environment variables to ensure Python finds installed packages ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ PYTHONPATH=/home/user/app WORKDIR /app # 3. Upgrade pip first (important for newer packages) RUN pip install --no-cache-dir --upgrade pip # 4. Copy requirements and install COPY --chown=user requirements.txt . # Adding --user ensures packages go to the path we set above RUN pip install --no-cache-dir --user -r requirements.txt # 5. Copy the rest of your app COPY --chown=user . . # 6. Run the app CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]