# ---------- builder stage ---------- FROM python:3.11-slim AS builder RUN apt-get update && \ apt-get install -y --no-install-recommends curl ca-certificates && \ curl -fsSL https://ollama.com/install.sh | sh && \ apt-get clean && rm -rf /var/lib/apt/lists/* # ---------- runtime stage ---------- FROM python:3.11-slim # runtime utils (ffmpeg only if you really need audio transcription) RUN apt-get update && \ apt-get install -y --no-install-recommends curl ca-certificates procps && \ apt-get clean && rm -rf /var/lib/apt/lists/* # copy ollama binary from builder COPY --from=builder /usr/local/bin/ollama /usr/local/bin/ollama # python deps COPY requirements.txt /tmp/ RUN pip install --no-cache-dir -U pip && \ pip install --no-cache-dir -r /tmp/requirements.txt WORKDIR /code COPY . . ENV OLLAMA_HOST=0.0.0.0:11434 EXPOSE 7860 11434 # health-check so Docker knows when the container is really ready HEALTHCHECK --interval=30s --timeout=3s --start-period=15s --retries=3 \ CMD curl -f http://localhost:7860/ || exit 1 CMD bash -c "\ ollama serve & \ while ! curl -s http://localhost:11434/api/tags >/dev/null; do \ echo 'waiting for ollama…'; sleep 1; done; \ ollama pull ${OLLAMA_MODEL:-tinyllama:1.1b-chat-q4_0}; \ exec gunicorn -b 0.0.0.0:7860 --workers 1 --timeout 120 app:app"