headless_browser / dockerfile
simoncck's picture
Rename Dockerfile to dockerfile
03e25b0 verified
# Use Python 3.11 slim as base image
FROM python:3.11-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive
# Set work directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
wget \
gnupg \
unzip \
curl \
xvfb \
x11vnc \
fluxbox \
wmctrl \
dbus-x11 \
&& rm -rf /var/lib/apt/lists/*
# Add Google Chrome repository and install Chrome
RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update \
&& apt-get install -y google-chrome-stable \
&& rm -rf /var/lib/apt/lists/*
# -------------------------------------------------------------
# Writable caches for non-root runtime
# -------------------------------------------------------------
ENV HOME=/tmp \
MPLCONFIGDIR=/tmp/matplotlib \
XDG_CACHE_HOME=/tmp/fontcache \
PLAYWRIGHT_BROWSERS_PATH=/tmp/ms-playwright
RUN mkdir -p /tmp/matplotlib /tmp/fontcache /tmp/ms-playwright \
&& chmod -R 777 /tmp/matplotlib /tmp/fontcache /tmp/ms-playwright
# Copy requirements file
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Let Selenium auto-download the correct driver
ENV SELENIUM_MANAGER_DRIVER=1
# Install Playwright browsers
RUN playwright install chromium
RUN playwright install-deps
# Copy application code
COPY . .
# Create directories for screenshots and logs
RUN mkdir -p /app/screenshots /app/logs
# Set proper permissions
RUN chmod -R 755 /app
# Expose port
EXPOSE 7860
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:7860/health || exit 1
# Start command
CMD ["python", "app.py"]