/ Home / Blog

Dockerfile with uv for Scrapy and Playwright

September 15, 2024

These are some Dockerfile examples for setting up a Scrapy project with uv and Playwright for quick web scraping and automation. Adjust the CMD to match your project’s requirements.

Dockerfile with uv #


FROM python:3.12
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv

COPY . .

RUN uv venv /opt/venv
# Use the virtual environment automatically
ENV VIRTUAL_ENV=/opt/venv

RUN uv pip install --system --no-cache -r requirements.txt

CMD scrapy crawl <spider-name>
CMD scrapy <command-name>

Dockerfile with uv and Playwright #

FROM python:3.12
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv

COPY . .

RUN uv venv /opt/venv
# Use the virtual environment automatically
ENV VIRTUAL_ENV=/opt/venv

ENV PLAYWRIGHT_BROWSERS_PATH=/playwright-browsers

RUN uv pip install --system \
    --no-cache -r requirements.txt

RUN playwright install --with-deps chromium \
    && chmod -Rf 777 $PLAYWRIGHT_BROWSERS_PATH


CMD scrapy crawl <spider-name>
CMD scrapy <command-name>

👋 Related posts in the Web Scraping series...