# ┌────────────────────────── build stage ──────────────────────────┐ FROM python:3.11-slim as builder WORKDIR /app # install build deps if any (none here), copy requirements COPY requirements.txt . RUN pip install --no-cache-dir --upgrade pip \ && pip install --no-cache-dir -r requirements.txt # └────────────────────────── final stage ──────────────────────────┘ FROM python:3.11-slim WORKDIR /app # copy only installed packages from builder (local pip cache) COPY --from=builder /usr/local/lib/python3.11/site-packages \ /usr/local/lib/python3.11/site-packages COPY --from=builder /usr/local/bin /usr/local/bin # copy app code COPY app.py . # expose port EXPOSE 8000 # use a non-root user if you like; for brevity we run as root. # run via Gunicorn WSGI server with 4 workers CMD ["gunicorn", "app:app", \ "--bind", "0.0.0.0:8000", \ "--workers", "4", \ "--threads", "4", \ "--access-logfile", "-", \ "--error-logfile", "-"]