FROM python:3.10-slim RUN useradd -m -u 1000 user RUN apt-get update && apt-get install -y --no-install-recommends build-essential git && rm -rf /var/lib/apt/lists/* USER user ENV PATH="/home/user/.local/bin:$PATH" ENV HF_HOME="/home/user/.cache/huggingface" ENV HF_HUB_DISABLE_SYMLINKS_WARNING=1 WORKDIR /app # Install dependencies first (cached layer) COPY --chown=user ./requirements.txt requirements.txt RUN pip install --no-cache-dir --upgrade -r requirements.txt # Copy all code COPY --chown=user . /app # Pre-download models and build index during Docker build # This means startup will be fast (seconds, not hours) RUN python startup.py EXPOSE 7860 CMD ["python", "web_app.py"]