# Stage 1: Build stage with Python and pip FROM python:3.9 AS builder # Create a non-root user RUN useradd -m -u 1000 user USER user # Set the working directory WORKDIR /app # Copy requirements file and install dependencies COPY --chown=user ./requirements.txt requirements.txt RUN pip install --no-cache-dir --upgrade -r requirements.txt # Stage 2: Runtime stage with Ollama FROM ollama/ollama:latest # Create the same non-root user for consistency RUN useradd -m -u 1000 user USER user # Set the environment PATH ENV PATH="/home/user/.local/bin:$PATH" # Set the working directory WORKDIR /app # Copy Python dependencies from the build stage COPY --from=builder /usr/local/lib/python3.9 /usr/local/lib/python3.9 COPY --from=builder /usr/local/bin /usr/local/bin # Copy the application code COPY --chown=user . /app # Expose the port for Streamlit EXPOSE 7860 # Add and set up the startup script COPY --chown=user ./startup.sh /app/startup.sh RUN chmod +x /app/startup.sh # Command to run the application CMD ["/app/startup.sh"]