Skip to content

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

Add enhanced Dockerfile with best practices

AMEYAMUKTEWAR415617d8e8e4
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 000000000..79181aaa9
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,56 @@
+# Use a specific Python 3.11 slim image as the base
+FROM python:3.11.3-slim
+
+# Set environment variables
+ENV PYTHONDONTWRITEBYTECODE=1 \
+ PYTHONUNBUFFERED=1
+
+# Install system dependencies
+RUN apt-get update && apt-get install -y --no-install-recommends \
+ git \
+ curl \
+ unzip \
+ xvfb \
+ libnss3 \
+ libatk-bridge2.0-0 \
+ libgtk-3-0 \
+ libxss1 \
+ libasound2 \
+ libx11-xcb1 \
+ libxcb-dri3-0 \
+ libdrm2 \
+ libgbm1 \
+ libxcomposite1 \
+ libxdamage1 \
+ libxrandr2 \
+ libxinerama1 \
+ libxcursor1 \
+ libxi6 \
+ libgl1-mesa-glx \
+ && rm -rf /var/lib/apt/lists/*
+
+# Create a non-root user
+RUN addgroup --system appgroup && adduser --system --ingroup appgroup appuser
+
+# Set work directory
+WORKDIR /app
+
+# Copy project files
+COPY . /app/
+
+# Change ownership to the non-root user
+RUN chown -R appuser:appgroup /app
+
+# Switch to non-root user
+USER appuser
+
+# Install Python dependencies
+RUN pip install --upgrade pip \
+ && pip install .
+
+# Define health check (example: adjust as needed)
+HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
+ CMD curl -f http://localhost:8000/health || exit 1
+
+# Define default command
+CMD ["python", "-m", "browser_use"]