Dockerfile118 lines · 4621 chars # syntax=docker/dockerfile:1
FROM python:3.12-slim
# Basic environment variables used by the build
ENV CODE_DIR=/app \
DATA_DIR=/data \
VENV_DIR=/app/.venv \
PATH="/app/.venv/bin:$PATH" \
UV_CACHE_DIR=/root/.cache/uv \
UV_LINK_MODE=copy \
UV_COMPILE_BYTECODE=1 \
UV_PYTHON_PREFERENCE=only-system \
IN_DOCKER=True
# Global user configuration (matching the project defaults)
ENV BROWSERUSE_USER="browseruse" \
DEFAULT_PUID=911 \
DEFAULT_PGID=911
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
# Use a reasonably strict shell to fail early on errors
SHELL ["/bin/bash", "-o", "pipefail", "-o", "errexit", "-o", "errtrace", "-o", "nounset", "-c"]
# Configure apt to be faster and less noisy
RUN echo 'Binary::apt::APT::Keep-Downloaded-Packages "1";' > /etc/apt/apt.conf.d/99keep-cache \
&& echo 'APT::Install-Recommends "0";' > /etc/apt/apt.conf.d/99no-install-recommends \
&& echo 'APT::Install-Suggests "0";' > /etc/apt/apt.conf.d/99no-install-suggests \
&& rm -f /etc/apt/apt.conf.d/docker-clean
# Install minimal system dependencies required for building and running
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-$TARGETARCH$TARGETVARIANT \
apt-get update -qq \
&& apt-get install -y --no-install-recommends \
ca-certificates curl unzip gnupg2 fontconfig \
nano iputils-ping dnsutils jq \
&& rm -rf /var/lib/apt/lists/*
# Bring in uv (Astral's uv image) to provide the uv tool
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
WORKDIR /app
# Only copy manifest first to leverage Docker build cache
COPY pyproject.toml uv.lock* /app/
RUN --mount=type=cache,target=/root/.cache,sharing=locked,id=cache-$TARGETARCH$TARGETVARIANT \
echo "[+] Setting up venv using uv in $VENV_DIR..." \
&& ( \
which uv && uv --version \
&& uv venv \
&& which python | grep "$VENV_DIR" \
&& python --version \
) | tee -a /VERSION.txt
# Install Chromium for Playwright/browser tests and font dependencies
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-$TARGETARCH$TARGETVARIANT \
echo "[+] Installing chromium browser from system packages..." \
&& apt-get update -qq \
&& apt-get install -y --no-install-recommends \
chromium \
fonts-unifont \
fonts-liberation \
fonts-dejavu-core \
fonts-freefont-ttf \
fonts-noto-core \
&& rm -rf /var/lib/apt/lists/* \
&& ln -s /usr/bin/chromium /usr/bin/chromium-browser \
&& ln -s /usr/bin/chromium /app/chromium-browser \
&& mkdir -p "/home/${BROWSERUSE_USER}/.config/chromium/Crash Reports/pending/" \
&& groupadd --system $BROWSERUSE_USER \
&& useradd --system --create-home --gid $BROWSERUSE_USER --groups audio,video $BROWSERUSE_USER \
&& usermod -u "$DEFAULT_PUID" "$BROWSERUSE_USER" \
&& groupmod -g "$DEFAULT_PGID" "$BROWSERUSE_USER" \
&& chown -R $BROWSERUSE_USER:$BROWSERUSE_USER "/home/${BROWSERUSE_USER}/.config" \
&& ( which chromium-browser && /usr/bin/chromium-browser --version ) | tee -a /VERSION.txt
# Install browser-use python dependencies in a cached layer
RUN --mount=type=cache,target=/root/.cache,sharing=locked,id=cache-$TARGETARCH$TARGETVARIANT \
echo "[+] Installing browser-use pip sub-dependencies..." \
&& ( \
uv sync --all-extras --no-dev --no-install-project \
&& echo -e '\n\n' \
) | tee -a /VERSION.txt
# Copy the rest of the code and install browser-use from source
COPY . /app
# Copy wrapper for proper --version support and install it
COPY entrypoint-browser-use.sh /usr/local/bin/browser-use
RUN chmod +x /usr/local/bin/browser-use
RUN --mount=type=cache,target=/root/.cache,sharing=locked,id=cache-$TARGETARCH$TARGETVARIANT \
echo "[+] Installing browser-use pip library from source..." \
&& ( \
uv sync --all-extras --locked --no-dev \
&& python -c "import browser_use; print('browser-use installed successfully')" \
&& echo -e '\n\n' \
) | tee -a /VERSION.txt
RUN mkdir -p "$DATA_DIR/profiles/default" \
&& chown -R $BROWSERUSE_USER:$BROWSERUSE_USER "$DATA_DIR" "$DATA_DIR"/* \
&& ( \
echo -e "\n\n[√] Finished Docker build successfully. Saving build summary in: /VERSION.txt" \
&& echo -e "PLATFORM=${TARGETPLATFORM} ARCH=$(uname -m) ($(uname -s) ${TARGETARCH} ${TARGETVARIANT})\n" \
&& echo -e "BUILD_END_TIME=$(date +\"%Y-%m-%d %H:%M:%S %s\")\n\n" \
) | tee -a /VERSION.txt
USER "$BROWSERUSE_USER"
VOLUME "$DATA_DIR"
EXPOSE 9242
EXPOSE 9222
ENTRYPOINT ["browser-use"]