# Use Python 3.9.11 FROM python:3.9.11 # Set the working directory WORKDIR /code # Copy the requirements file COPY ./requirements.txt /code/requirements.txt # Install system dependencies and Python packages RUN apt-get update && apt-get install -y \ tesseract-ocr \ libtesseract-dev \ && pip install --no-cache-dir --upgrade -r /code/requirements.txt \ && rm -rf /var/lib/apt/lists/* # Add a non-root user RUN useradd -m user # Set environment variables ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ HF_HOME=/home/user/.cache/huggingface \ TESSERACT_CMD=/usr/bin/tesseract # Create the cache directory and set permissions RUN mkdir -p /home/user/.cache/huggingface && chown -R user:user /home/user/.cache # Switch to the non-root user USER user # Set the working directory for the user WORKDIR $HOME/app # Copy the content into /home/user/app with the correct permissions COPY --chown=user:user . $HOME/app # Expose the port the app runs on EXPOSE 7860 # Command to run the application CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]