FROM pytorch/pytorch:2.7.0-cuda12.6-cudnn9-runtime # Install system dependencies as root first RUN apt-get update && apt-get install -y \ # libGL runtime needed by OpenCV when non-headless builds are present libgl1 \ libgl1-mesa-dri \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender-dev \ libgomp1 \ libgtk-3-0 \ libgdk-pixbuf2.0-0 \ libxss1 \ libnss3 \ libxrandr2 \ libasound2 \ libpangocairo-1.0-0 \ libatk1.0-0 \ libcairo-gobject2 \ libfontconfig1 \ libx11-6 \ libx11-xcb1 \ libxcb1 \ libxcomposite1 \ libxcursor1 \ libxdamage1 \ libxfixes3 \ libxi6 \ libxrandr2 \ libxrender1 \ libxss1 \ libxtst6 \ && rm -rf /var/lib/apt/lists/* # 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 the working directory to the user's home directory WORKDIR $HOME/app # Try and run pip command after setting the user with `USER user` to avoid permission issues with Python RUN pip install --no-cache-dir --upgrade pip # Copy requirements first for better caching COPY --chown=user requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy application code COPY --chown=user . . # Expose port EXPOSE 7860 # Set environment variables ENV PYTHONUNBUFFERED=1 ENV HF_HUB_DISABLE_TELEMETRY=1 # Run the application CMD ["python", "app.py"]