# Use the official Python 3.9 image as the base image FROM python:3.9 # Create a non-root user and switch to it RUN useradd -m -u 1000 user ENV PATH="/home/user/.local/bin:$PATH" # Set the working directory WORKDIR /app # Install system dependencies (Tesseract OCR) as root USER root RUN apt-get update -y && \ apt-get install -y tesseract-ocr && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* # Clean up to reduce image size # Ensure /app is writable by the non-root user RUN chown user:user /app # Create a directory for model weights (optional, if you plan to add models later) RUN mkdir -p /app/models && chown user:user /app/models # Switch back to the non-root user USER user # Copy and install Python dependencies COPY --chown=user ./requirements.txt requirements.txt RUN pip install --no-cache-dir --upgrade -r requirements.txt # Copy the rest of the application code COPY --chown=user . /app # Set the command to run the application CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]