Skip to content

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

Refactor Dockerfile: apply layered optimization, patchright, and entrypoint updates

Ameya-2003cf23c5ca21e1
diff --git a/Dockerfile b/Dockerfile
index bbf3422e7..9abfe7005 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,40 +1,38 @@
+# 1. Base image
FROM python:3.11-slim
-ENV PYTHONDONTWRITEBYTECODE=1 \
- PYTHONUNBUFFERED=1
+# 2. Create a non-root user (don’t switch yet)
+RUN groupadd appgroup \
+ && useradd -m -g appgroup appuser
-# Install minimal system dependencies required for Chrome
-RUN apt-get update -qq && apt-get install -y --no-install-recommends -qq \
- git \
- curl \
- unzip \
- libnss3 \
- libxss1 \
- libasound2 \
- libx11-xcb1 \
- && apt-get clean \
- && rm -rf /var/lib/apt/lists/*
-
-# Create non-root user
-RUN groupadd appgroup && useradd -m -g appgroup appuser
+# 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 \
+ && rm -rf /var/lib/apt/lists/*
+# 4. Set working directory
WORKDIR /app
-# Copy project files
-COPY . /app/
+# 5. Copy only dependency manifest
+COPY pyproject.toml /app/
-# Change ownership
-RUN chown -R appuser:appgroup /app
+# 6. Install patchright (version from pyproject.toml)
+RUN python3 -m pip install --upgrade pip --quiet \
+ && python3 -m pip install patchright --quiet
-# Switch to non-root user
-USER appuser
+# 7. Install Chromium via patchright
+RUN patchright install --with-deps --no-shell chromium
-# Build Python package
-RUN python3 setup.py sdist
+# 8. Copy the rest of the codebase
+COPY . /app
-# Install Python dependencies from built package
-RUN python3 -m pip install --upgrade pip --quiet \
- && python3 -m pip install dist/*.tar.gz --quiet
+# 9. Install the application package
+RUN python3 -m pip install . --quiet
+
+# 10. Switch to non-root user
+USER appuser
-# Default command
-CMD ["python3", "-m", "browser_use"]
+# 11. Entrypoint
+ENTRYPOINT ["browser-use"]