IAGO / Dockerfile
James Frecheville
Move browser installation to build phase and remove runtime installation
85dc94a
FROM python:3.10-slim
# Install system dependencies for Playwright and other packages
RUN apt-get update && apt-get install -y \
libnss3 \
libnspr4 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libxcomposite1 \
libxdamage1 \
libatspi2.0-0 \
libxrandr2 \
libgbm1 \
libasound2 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libgdk-pixbuf2.0-0 \
libgtk-3-0 \
libgl1-mesa-glx \
libsm6 \
libxext6 \
libx11-xcb1 \
libxcb-dri3-0 \
libdrm2 \
libxkbcommon0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libasound2 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libgdk-pixbuf2.0-0 \
libgtk-3-0 \
libgl1-mesa-glx \
libsm6 \
libxext6 \
ffmpeg \
xvfb \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Create a non-root user
RUN useradd -m -u 1000 user && \
mkdir -p /home/user/.cache && \
chown -R user:user /home/user/.cache
# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Install Playwright browsers as root
RUN mkdir -p /home/user/.cache/ms-playwright && \
playwright install chromium && \
playwright install-deps && \
chown -R user:user /home/user/.cache/ms-playwright
# Copy the rest of the application
COPY . .
RUN chown -R user:user /app
# Set environment variables
ENV GRADIO_SERVER_NAME=0.0.0.0
ENV GRADIO_SERVER_PORT=7860
ENV GRADIO_ANALYTICS_ENABLED=false
ENV GRADIO_ALLOW_FLAGGING=false
ENV GRADIO_QUEUE_ENABLED=false
ENV DISPLAY=:99
ENV PLAYWRIGHT_BROWSERS_PATH=/home/user/.cache/ms-playwright
# Switch to non-root user
USER user
# Expose the port
EXPOSE 7860
# Run the application with Xvfb
CMD Xvfb :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & python app.py