# Use the NVIDIA CUDA image as the base FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu20.04 # Set non-interactive mode for apt-get ENV DEBIAN_FRONTEND=noninteractive # Install system dependencies RUN apt-get update && apt-get install -y \ python3.10 \ python3.10-venv \ python3.10-dev \ python3-pip \ cmake \ build-essential \ && rm -rf /var/lib/apt/lists/* # Set up a new user named "user" with user ID 1000 RUN useradd -m -u 1000 user # Set the working directory WORKDIR /app # Create and activate virtual environment RUN python3.10 -m venv /app/venv ENV PATH="/app/venv/bin:$PATH" # Copy the requirements file COPY requirements.txt . # Install Python dependencies RUN . /app/venv/bin/activate && \ pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # Install llama-cpp-python with CUDA support RUN . /app/venv/bin/activate && \ pip install llama-cpp-python \ --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cu121 # Copy the rest of the application code COPY . . # Change ownership of the app directory to the user RUN chown -R user:user /app # Switch to the "user" user USER user # Set the PATH to include the user's local bin directory ENV PATH="/home/user/.local/bin:$PATH" # Run the application CMD ["/app/venv/bin/uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]