Skip to content

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

fix spelling

Nick Sweeting3d0e265842f3
diff --git a/Dockerfile b/Dockerfile
index f899bca52..ea4861d49 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,37 +1,180 @@
-# 1. Base image
+# 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
+# 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
+# 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
+#
+# Read more about [developing browseruse](https://github.com/browseruse/browseruse#browseruse-development).
+
+#########################################################################################
+
+
FROM python:3.11-slim
-# 2. Create a non-root user (don’t switch yet)
-RUN groupadd appgroup \
- && useradd -m -g appgroup appuser
+LABEL name="browseruse" \
+ maintainer="Nick Sweeting <[email protected]>" \
+ description="Make websites accessible for AI agents. Automate tasks online with ease." \
+ homepage="https://github.com/browser-use/browser-use" \
+ documentation="https://docs.browser-use.com" \
+ org.opencontainers.image.title="browseruse" \
+ org.opencontainers.image.vendor="browseruse" \
+ org.opencontainers.image.description="Make websites accessible for AI agents. Automate tasks online with ease." \
+ org.opencontainers.image.source="https://github.com/browser-use/browser-use" \
+ com.docker.image.source.entrypoint="Dockerfile" \
+ com.docker.desktop.extension.api.version=">= 1.4.7" \
+ com.docker.desktop.extension.icon="https://avatars.githubusercontent.com/u/192012301?s=200&v=4" \
+ com.docker.extension.publisher-url="https://browser-use.com" \
+ com.docker.extension.screenshots='[{"alt": "Screenshot of CLI splashscreen", "url": "https://github.com/user-attachments/assets/3606d851-deb1-439e-ad90-774e7960ded8"}, {"alt": "Screenshot of CLI running", "url": "https://github.com/user-attachments/assets/d018b115-95a4-4ac5-8259-b750bc5f56ad"}]' \
+ com.docker.extension.detailed-description='See here for detailed documentation: https://docs.browser-use.com' \
+ com.docker.extension.changelog='See here for release notes: https://github.com/browser-use/browser-use/releases' \
+ com.docker.extension.categories='web,utility-tools,ai'
-# 3. Install base APT packages
-RUN apt-get update -qq \
- && apt-get install -y --no-install-recommends -qq \
- unzip libnss3 libxss1 libasound2 libx11-xcb1 \
- curl git grep \
- && rm -rf /var/lib/apt/lists/*
+ARG TARGETPLATFORM
+ARG TARGETOS
+ARG TARGETARCH
+ARG TARGETVARIANT
-# 4. Set working directory
-WORKDIR /app
+######### Environment Variables #################################
+
+# Global system-level config
+ENV TZ=UTC \
+ LANGUAGE=en_US:en \
+ LC_ALL=C.UTF-8 \
+ LANG=C.UTF-8 \
+ DEBIAN_FRONTEND=noninteractive \
+ APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 \
+ PYTHONIOENCODING=UTF-8 \
+ PYTHONUNBUFFERED=1 \
+ PIP_DISABLE_PIP_VERSION_CHECK=1 \
+ npm_config_loglevel=error \
+ IN_DOCKER=True
+
+# User config
+ENV BROWSERUSE_USER="browseruse" \
+ DEFAULT_PUID=911 \
+ DEFAULT_PGID=911
+
+# Paths
+ENV CODE_DIR=/app \
+ CONFIG_DIR=/home/$BROWSERUSE_USER/.config/browseruse
+
+# Build shell config
+SHELL ["/bin/bash", "-o", "pipefail", "-o", "errexit", "-o", "errtrace", "-o", "nounset", "-c"]
+
+# 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 \
+ && echo 'APT::Install-Suggests "0";' > /etc/apt/apt.conf.d/99no-intall-suggests \
+ && rm -f /etc/apt/apt.conf.d/docker-clean
-# 5. Copy only dependency manifest
+# Print debug info about build and save it to disk, for human eyes only, not used by anything else
+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 \
+ && uname -a \
+ && cat /etc/os-release | head -n7 \
+ && which bash && bash --version | head -n1 \
+ && which dpkg && dpkg --version | head -n1 \
+ && echo -e '\n\n' && env && echo -e '\n\n' \
+ && which python && python --version \
+ && which pip && pip --version \
+ && echo -e '\n\n' \
+ ) | tee -a /VERSION.txt
+
+# Create non-privileged user for browseruse and chrome
+RUN echo "[*] Setting up $BROWSERUSE_USER user uid=${DEFAULT_PUID}..." \
+ && 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" \
+ && 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
+ # https://docs.linuxserver.io/general/understanding-puid-and-pgid
+
+# 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 \
+ && mkdir -p /etc/apt/keyrings \
+ && apt-get update -qq \
+ && apt-get install -qq -y -t bookworm-backports \
+ # 1. packaging dependencies
+ apt-transport-https ca-certificates apt-utils gnupg2 curl wget \
+ # 2. docker and init system dependencies:
+ zlib1g-dev dumb-init gosu cron unzip grep dnsutils \
+ # 3. frivolous CLI helpers to make debugging failed archiving easierL
+ 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 \
+ # 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/
-# 6. Install playwright (version from pyproject.toml)
-RUN pip install playwright=="$(grep -oP '(p....right>=\K[0-9.]+' pyproject.toml)"
+# Install playwright (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)" \
+ && ( \
+ which playwright && playwright --version \
+ && echo -e '\n\n' \
+ ) | tee -a /VERSION.txt
# 7. Install Chromium via patchright
-RUN playwright install --with-deps --no-shell chromium
+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 \
+ 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" \
+ && ( \
+ which chromium-browser && /usr/bin/chromium-browser --version \
+ && echo -e '\n\n' \
+ ) | tee -a /VERSION.txt
# 8. Copy the rest of the codebase
COPY . /app
# 9. Install the application package
-RUN pip install -e .
+RUN pip install -e ".[all]"
# 10. Switch to non-root user
-USER appuser
+USER browseruse
+
+RUN mkdir -p "$CONFIG_DIR" \
+ && chown browseruse:browseruse "$CONFIG_DIR" "$CONFIG_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
+RUN which browser-use && browser-use --version 2>&1 | tee -a /VERSION.txt
+
+VOLUME "$CONFIG_DIR"
+EXPOSE 9242
+EXPOSE 9222
+
+# HEALTHCHECK --interval=30s --timeout=20s --retries=15 \
+# CMD curl --silent 'http://localhost:8000/health/' | grep -q 'OK'
-# 11. Entrypoint
ENTRYPOINT ["browser-use"]