Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

use uv for faster docker build

Nick Sweeting211d7bac630c
diff --git a/Dockerfile b/Dockerfile
index 70e843cdb..8d5892f58 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,18 +1,18 @@
+# syntax=docker/dockerfile:1
+# check=skip=SecretsUsedInArgOrEnv
+
# This is the Dockerfile for browser-use, it bundles the following dependencies:
# python3, pip, playwright, chromium, browser-use and its dependencies.
# Usage:
-# git submodule update --init --recursive
-# git pull --recurse-submodules
+# git clone https://github.com/browser-use/browser-use.git && cd browser-use
# docker build . -t browseruse --no-cache
-# docker run -v "$PWD/data":/data browseruse init
-# docker run -v "$PWD/data":/data browseruse add 'https://example.com'
-# docker run -v "$PWD/data":/data -it browseruse manage createsuperuser
-# docker run -v "$PWD/data":/data -p 8000:8000 browseruse server
+# docker run -v "$PWD/data":/data browseruse
+# docker run -v "$PWD/data":/data browseruse --version
# Multi-arch build:
# docker buildx create --use
-# docker buildx build . --platform=linux/amd64,linux/arm64--push -t browseruse/browseruse:0.7.5 -t browseruse/browseruse:dev
+# docker buildx build . --platform=linux/amd64,linux/arm64--push -t browseruse/browseruse:some-tag
#
-# Read more about [developing browseruse](https://github.com/browseruse/browseruse#browseruse-development).
+# Read more: https://docs.browser-use.com
#########################################################################################
@@ -54,6 +54,9 @@ ENV TZ=UTC \
PYTHONIOENCODING=UTF-8 \
PYTHONUNBUFFERED=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
+ UV_SYSTEM_PYTHON=1 \
+ UV_CACHE_DIR=/root/.cache/uv \
+ UV_LINK_MODE=copy \
npm_config_loglevel=error \
IN_DOCKER=True
@@ -64,11 +67,14 @@ ENV BROWSERUSE_USER="browseruse" \
# Paths
ENV CODE_DIR=/app \
- CONFIG_DIR=/home/$BROWSERUSE_USER/.config/browseruse
+ DATA_DIR=/data \
+ VENV_DIR=/app/.venv/bin
# Build shell config
SHELL ["/bin/bash", "-o", "pipefail", "-o", "errexit", "-o", "errtrace", "-o", "nounset", "-c"]
+COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
+
# Force apt to leave downloaded binaries in /var/cache/apt (massively speeds up Docker builds)
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-intall-recommends \
@@ -80,7 +86,7 @@ RUN (echo "[i] Docker build for Browser Use $(cat /VERSION.txt) starting..." \
&& echo "PLATFORM=${TARGETPLATFORM} ARCH=$(uname -m) ($(uname -s) ${TARGETARCH} ${TARGETVARIANT})" \
&& echo "BUILD_START_TIME=$(date +"%Y-%m-%d %H:%M:%S %s") TZ=${TZ} LANG=${LANG}" \
&& echo \
- && echo "CODE_DIR=${CODE_DIR} CONFIG_DIR=${CONFIG_DIR} PATH=${PATH}" \
+ && echo "CODE_DIR=${CODE_DIR} DATA_DIR=${DATA_DIR} PATH=${PATH}" \
&& echo \
&& uname -a \
&& cat /etc/os-release | head -n7 \
@@ -89,6 +95,7 @@ RUN (echo "[i] Docker build for Browser Use $(cat /VERSION.txt) starting..." \
&& echo -e '\n\n' && env && echo -e '\n\n' \
&& which python && python --version \
&& which pip && pip --version \
+ && which uv && uv --version \
&& echo -e '\n\n' \
) | tee -a /VERSION.txt
@@ -98,6 +105,10 @@ RUN echo "[*] Setting up $BROWSERUSE_USER user uid=${DEFAULT_PUID}..." \
&& useradd --system --create-home --gid $BROWSERUSE_USER --groups audio,video $BROWSERUSE_USER \
&& usermod -u "$DEFAULT_PUID" "$BROWSERUSE_USER" \
&& groupmod -g "$DEFAULT_PGID" "$BROWSERUSE_USER" \
+ && mkdir -p /data \
+ && mkdir -p /home/$BROWSERUSE_USER/.config \
+ && chown -R $BROWSERUSE_USER:$BROWSERUSE_USER /home/$BROWSERUSE_USER \
+ && ln -s $DATA_DIR /home/$BROWSERUSE_USER/.config/browseruse \
&& echo -e "\nBROWSERUSE_USER=$BROWSERUSE_USER PUID=$(id -u $BROWSERUSE_USER) PGID=$(id -g $BROWSERUSE_USER)\n\n" \
| tee -a /VERSION.txt
# DEFAULT_PUID and DEFAULT_PID are overridden by PUID and PGID in /bin/docker_entrypoint.sh at runtime
@@ -106,10 +117,10 @@ RUN echo "[*] Setting up $BROWSERUSE_USER user uid=${DEFAULT_PUID}..." \
# Install base apt dependencies (adding backports to access more recent apt updates)
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-$TARGETARCH$TARGETVARIANT \
echo "[+] Installing APT base system dependencies for $TARGETPLATFORM..." \
- && echo 'deb https://deb.debian.org/debian bookworm-backports main contrib non-free' > /etc/apt/sources.list.d/backports.list \
+# && echo 'deb https://deb.debian.org/debian bookworm-backports main contrib non-free' > /etc/apt/sources.list.d/backports.list \
&& mkdir -p /etc/apt/keyrings \
&& apt-get update -qq \
- && apt-get install -qq -y -t bookworm-backports \
+ && apt-get install -qq -y --no-install-recommends \
# 1. packaging dependencies
apt-transport-https ca-certificates apt-utils gnupg2 curl wget \
# 2. docker and init system dependencies:
@@ -118,65 +129,67 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-$TARGETARCH$T
tree nano iputils-ping dnsutils jq yq procps \
# 4. browser dependencies:
libnss3 libxss1 libasound2 libx11-xcb1 \
- # fontconfig fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-khmeros fonts-kacst fonts-symbola fonts-noto fonts-freefont-ttf \
- # at-spi2-common fonts-liberation fonts-noto-color-emoji fonts-tlwg-loma-otf fonts-unifont libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 libavahi-client3 \
- # libavahi-common-data libavahi-common3 libcups2 libfontenc1 libice6 libnspr4 libnss3 libsm6 libunwind8 \
- # libxaw7 libxcomposite1 libxdamage1 libxfont2 \
+ fontconfig fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-khmeros fonts-kacst fonts-symbola fonts-noto fonts-freefont-ttf \
+ at-spi2-common fonts-liberation fonts-noto-color-emoji fonts-tlwg-loma-otf fonts-unifont libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 libavahi-client3 \
+ libavahi-common-data libavahi-common3 libcups2 libfontenc1 libice6 libnspr4 libnss3 libsm6 libunwind8 \
+ libxaw7 libxcomposite1 libxdamage1 libxfont2 \
# 5. x11/xvfb dependencies:
# libxkbfile1 libxmu6 libxpm4 libxt6 x11-xkb-utils x11-utils xfonts-encodings \
# xfonts-scalable xfonts-utils xserver-common xvfb \
&& rm -rf /var/lib/apt/lists/*
-
# Copy only dependency manifest
WORKDIR /app
COPY pyproject.toml /app/
-# Install playwright (with version from pyproject.toml)
+# Install playwright using pip (with version from pyproject.toml)
RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked,id=pip-$TARGETARCH$TARGETVARIANT \
- pip install "$(ggrep -oP 'p....right>=([0-9.])+' pyproject.toml)" \
+ uv pip install "$(grep -oP 'p....right>=([0-9.])+' pyproject.toml)" \
&& ( \
which playwright && playwright --version \
&& echo -e '\n\n' \
) | tee -a /VERSION.txt
-# 7. Install Chromium via patchright
-RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-$TARGETARCH$TARGETVARIANT --mount=type=cache,target=/root/.cache/pip,sharing=locked,id=pip-$TARGETARCH$TARGETVARIANT --mount=type=cache,target=/root/.cache/ms-playwright,sharing=locked,id=browsers-$TARGETARCH$TARGETVARIANT \
+# Install Chromium using playwright
+RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-$TARGETARCH$TARGETVARIANT \
+ --mount=type=cache,target=/root/.cache/uv,sharing=locked,id=uv-$TARGETARCH$TARGETVARIANT \
+ --mount=type=cache,target=/root/.cache/pip,sharing=locked,id=pip-$TARGETARCH$TARGETVARIANT \
+ --mount=type=cache,target=/root/.cache/ms-playwright,sharing=locked,id=browsers-$TARGETARCH$TARGETVARIANT \
echo "[+] Installing Browser binary dependencies to /root/.cache/ms-playwright..." \
&& playwright install --with-deps --no-shell chromium \
&& export CHROME_BINARY="$(python -c 'from playwright.sync_api import sync_playwright; print(sync_playwright().start().chromium.executable_path)')" \
&& ln -s "$CHROME_BINARY" /usr/bin/chromium-browser \
&& mkdir -p "/home/${BROWSERUSE_USER}/.config/chromium/Crash Reports/pending/" \
- && chown -R "$DEFAULT_PUID:$DEFAULT_PGID" "/home/${BROWSERUSE_USER}/.config" \
+ && chown -R "$BROWSERUSE_USER:$BROWSERUSE_USER" "/home/${BROWSERUSE_USER}/.config" \
&& ( \
which chromium-browser && /usr/bin/chromium-browser --version \
&& echo -e '\n\n' \
) | tee -a /VERSION.txt
-# 8. Copy the rest of the codebase
+# Copy the rest of the browser-use codebase
COPY . /app
-# 9. Install the browser-use package and all its dependencies
-RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked,id=pip-$TARGETARCH$TARGETVARIANT \
- pip install -e ".[all]" \
+# Install the browser-use package and all of its optional dependencies
+RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked,id=pip-$TARGETARCH$TARGETVARIANT --mount=type=cache,target=/root/.cache/uv,sharing=locked,id=uv-$TARGETARCH$TARGETVARIANT \
+ uv pip install -e ".[all]" \
&& ( \
- which browser-use \
+ uv pip show browser-use \
+ && which browser-use \
&& browser-use --version 2>&1 \
&& echo -e '\n\n' \
) | tee -a /VERSION.txt
-# 10. Switch to non-root user
-USER browseruse
-
-RUN mkdir -p "$CONFIG_DIR" \
- && chown browseruse:browseruse "$CONFIG_DIR" "$CONFIG_DIR/*" \
+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
-VOLUME "$CONFIG_DIR"
+
+USER "$BROWSERUSE_USER"
+VOLUME "$DATA_DIR"
EXPOSE 9242
EXPOSE 9222