# Use a lightweight Python image FROM python:3.10-slim # Set working directory WORKDIR /app # System dependencies not needed for Pillow/Torch CPU in this case. # If you add opencv-python later, you might need libgl1 and libglib2.0-0. # Copy requirements COPY requirements.txt . # Install PyTorch CPU ONLY (Crucial for small droplets to save space) # This must be run BEFORE installing requirements.txt if requirements.txt contained torch, # but here we run it explicitly to ensure we get the CPU version. RUN pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu # Install other requirements RUN pip install --no-cache-dir -r requirements.txt # Set up a new user named "user" with user ID 1000 RUN useradd -m -u 1000 user # Switch to the "user" user USER user # Set home to the user's home directory ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Set working directory to the user's home directory WORKDIR $HOME/app # Copy the current directory contents into the container at $HOME/app setting the owner to the user COPY --chown=user . $HOME/app # Expose port 7860 EXPOSE 7860 # Run the app on port 7860 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]