FROM python:3.9-slim # System dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential gcc libffi-dev libpq-dev curl && \ apt-get clean && rm -rf /var/lib/apt/lists/* # Create and switch to non-root user RUN useradd -m -u 1000 user USER user # Set environment ENV PATH="/home/user/.local/bin:$PATH" WORKDIR /app # Copy requirements and install COPY --chown=user requirements.txt . RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # Copy source code COPY --chown=user . /app # Expose port (optional for readability) EXPOSE 7860 # Use Uvicorn with proper worker class if using FastAPI or async CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "2"]