# Use a lightweight Python image FROM python:3.9 # Create a non-root user RUN useradd -u 1000 user ENV PATH="/home/user/.local/bin:$PATH" # Set a writable cache directory for Hugging Face Transformers ENV TRANSFORMERS_CACHE=/app/.cache ENV HF_HOME=/app/.cache # Set the working directory inside the container WORKDIR /app # Copy the dependencies and install them as root COPY requirements.txt . RUN mkdir -p /app/.cache && chown -R user:user /app/.cache RUN pip install --no-cache-dir -r requirements.txt # Switch to the non-root user after installing dependencies USER user COPY . . # Run the FastAPI app with Uvicorn CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]