Docker (tùy chọn)
Docker is optional. Use it only if you want a containerized gateway or to validate the Docker flow.Docker có phù hợp với tôi không?
- Có: bạn muốn một môi trường gateway tách biệt, dùng xong bỏ, hoặc chạy OpenClaw trên máy chủ không có cài đặt cục bộ.
- No: you’re running on your own machine and just want the fastest dev loop. Use the normal install flow instead.
- Sandboxing note: agent sandboxing uses Docker too, but it does not require the full gateway to run in Docker. See Sandboxing.
- Gateway chạy trong container (toàn bộ OpenClaw trong Docker)
- Sandbox Tác tử theo phiên (gateway trên host + công cụ tác tử được cô lập bằng Docker)
Yêu cầu
- Docker Desktop (hoặc Docker Engine) + Docker Compose v2
- Đủ dung lượng đĩa cho image + log
Gateway chạy trong container (Docker Compose)
Khởi động nhanh (khuyến nghị)
Từ thư mục gốc của repo:- build image gateway
- chạy trình hướng dẫn onboarding
- in ra các gợi ý thiết lập nhà cung cấp (tùy chọn)
- khởi động gateway qua Docker Compose
- tạo token gateway và ghi vào
.env
OPENCLAW_DOCKER_APT_PACKAGES— cài thêm các gói apt trong quá trình buildOPENCLAW_EXTRA_MOUNTS— thêm các bind mount từ hostOPENCLAW_HOME_VOLUME— lưu/home/nodetrong một volume có tên
- Mở
http://127.0.0.1:18789/trong trình duyệt. - Dán token vào Control UI (Settings → token).
- Need the URL again? Run
docker compose run --rm openclaw-cli dashboard --no-open.
~/.openclaw/~/.openclaw/workspace
Luồng thủ công (compose)
Để quản lý Docker hằng ngày dễ dàng hơn, hãy cài đặtClawDock:
clawdock-start, clawdock-stop, clawdock-dashboard, v.v. Chạy clawdock-help để xem tất cả các lệnh.
Xem ClawDock Helper README để biết chi tiết.
Luồng thủ công (compose)
docker compose ... from the repo root. Nếu bạn đã bật
OPENCLAW_EXTRA_MOUNTS hoặc OPENCLAW_HOME_VOLUME, script thiết lập sẽ ghi
docker-compose.extra.yml; hãy include nó khi chạy Compose ở nơi khác:
Token Control UI + ghép cặp (Docker)
Ghi chú:Mount bổ sung (tùy chọn)
If you want to mount additional host directories into the containers, setOPENCLAW_EXTRA_MOUNTS before running docker-setup.sh. Đây là các ví dụ, không phải danh sách đầy đủ.
Ví dụ:
- Đường dẫn phải được chia sẻ với Docker Desktop trên macOS/Windows.
- Nếu bạn chỉnh sửa
OPENCLAW_EXTRA_MOUNTS, hãy chạy lạidocker-setup.shđể tạo lại file compose bổ sung. docker-compose.extra.ymlđược tạo. Don’t hand-edit it.
Lưu toàn bộ home của container (tùy chọn)
If you want/home/node to persist across container recreation, set a named
volume via OPENCLAW_HOME_VOLUME. This creates a Docker volume and mounts it at
/home/node, while keeping the standard config/workspace bind mounts. Use a
named volume here (not a bind path); for bind mounts, use
OPENCLAW_EXTRA_MOUNTS.
Ví dụ:
- Nếu bạn thay đổi
OPENCLAW_HOME_VOLUME, hãy chạy lạidocker-setup.shđể tạo lại file compose bổ sung. - Volume có tên sẽ tồn tại cho đến khi bị xóa bằng
docker volume rm <name>.
Cài thêm gói apt (tùy chọn)
If you need system packages inside the image (for example, build tools or media libraries), setOPENCLAW_DOCKER_APT_PACKAGES before running docker-setup.sh.
This installs the packages during the image build, so they persist even if the
container is deleted.
Nếu bạn muốn container đầy đủ tính năng hơn, hãy dùng các tùy chọn opt-in sau:
- Đóng gói phụ thuộc hệ thống vào image (lặp lại được + bền vững):
- Nếu bạn thay đổi
OPENCLAW_DOCKER_APT_PACKAGES, hãy chạy lạidocker-setup.shđể build lại image.
Container đầy đủ tính năng cho người dùng nâng cao (tùy chọn)
The default Docker image is security-first and runs as the non-rootnode
user. This keeps the attack surface small, but it means:
- không cài gói hệ thống lúc runtime
- không có Homebrew mặc định
- không kèm trình duyệt Chromium/Playwright
OPENCLAW_DOCKER_APT_PACKAGES thay vì dùng --with-deps lúc runtime.
- Lưu các bản tải trình duyệt Playwright:
- Đóng gói phụ thuộc hệ thống vào image (lặp lại được + bền vững):
- Cài trình duyệt Playwright không cần
npx(tránh xung đột override npm):
- Lưu các bản tải trình duyệt Playwright:
- Đặt
PLAYWRIGHT_BROWSERS_PATH=/home/node/.cache/ms-playwrighttrongdocker-compose.yml. - Đảm bảo
/home/nodeđược giữ lại quaOPENCLAW_HOME_VOLUME, hoặc mount/home/node/.cache/ms-playwrightquaOPENCLAW_EXTRA_MOUNTS.
Quyền + EACCES
The image runs asnode (uid 1000). If you see permission errors on
/home/node/.openclaw, make sure your host bind mounts are owned by uid 1000.
Dùng container CLI để cấu hình kênh, rồi khởi động lại gateway nếu cần.
Build lại nhanh hơn (khuyến nghị)
To speed up rebuilds, order your Dockerfile so dependency layers are cached. This avoids re-runningpnpm install unless lockfiles change:
Thiết lập kênh (tùy chọn)
Tài liệu: WhatsApp, Telegram, Discord WhatsApp (QR):OpenAI Codex OAuth (Docker không giao diện)
If you pick OpenAI Codex OAuth in the wizard, it opens a browser URL and tries to capture a callback onhttp://127.0.0.1:1455/auth/callback. In Docker or
headless setups that callback can show a browser error. Copy the full redirect
URL you land on and paste it back into the wizard to finish auth.
Kiểm tra sức khỏe
Kiểm thử E2E smoke test (Docker)
Kiểm thử import QR smoke test (Docker)
Ghi chú
- Gateway bind mặc định là
lancho việc dùng trong container. - Dockerfile CMD uses
--allow-unconfigured; mounted config withgateway.modenotlocalwill still start. Override CMD to enforce the guard. - Container gateway là nguồn chân lý cho các phiên (
~/.openclaw/agents/<agentId>/sessions/).
Sandbox Tác tử (gateway trên host + công cụ Docker)
Đào sâu: SandboxingNó làm gì
Whenagents.defaults.sandbox is enabled, non-main sessions run tools inside a Docker
container. The gateway stays on your host, but the tool execution is isolated:
- phạm vi:
"agent"theo mặc định (một container + workspace cho mỗi tác tử) - Mỗi tác tử một container
- Quyền truy cập workspace tác tử:
workspaceAccess: "none"(mặc định) dùng~/.openclaw/sandboxes - Tự động dọn dẹp: nhàn rỗi > 24h HOẶC tuổi > 7 ngày
- Mạng:
nonetheo mặc định (chỉ bật khi bạn cần egress) - Cho phép mặc định:
exec,process,read,write,edit,sessions_list,sessions_history,sessions_send,sessions_spawn,session_status
scope: "shared" disables cross-session isolation. All sessions share
one container and one workspace.
Hồ sơ sandbox theo từng tác tử (đa tác tử)
If you use multi-agent routing, each agent can override sandbox + tool settings:agents.list[].sandbox and agents.list[].tools (plus agents.list[].tools.sandbox.tools). This lets you run
mixed access levels in one gateway:
- Toàn quyền (tác tử cá nhân)
- Công cụ chỉ đọc + workspace chỉ đọc (tác tử gia đình/công việc)
- Không có công cụ filesystem/shell (tác tử công khai)
agents.defaults.sandbox.docker:
network, user, pidsLimit, memory, memorySwap, cpus, ulimits,
seccompProfile, apparmorProfile, dns, extraHosts.
Hành vi mặc định
- Image:
openclaw-sandbox:bookworm-slim - Mỗi tác tử một container
- Quyền truy cập workspace tác tử:
workspaceAccess: "none"(mặc định) dùng~/.openclaw/sandboxes"ro"giữ workspace sandbox tại/workspacevà mount workspace tác tử ở chế độ chỉ đọc tại/agent(vô hiệuwrite/edit/apply_patch)"rw"mount workspace tác tử đọc/ghi tại/workspace
- Tự động dọn dẹp: nhàn rỗi > 24h HOẶC tuổi > 7 ngày
- Mạng:
nonetheo mặc định (chỉ bật khi bạn cần egress) - Cho phép mặc định:
exec,process,read,write,edit,sessions_list,sessions_history,sessions_send,sessions_spawn,session_status - Từ chối mặc định:
browser,canvas,nodes,cron,discord,gateway
Bật sandboxing
Lệnh này buildopenclaw-sandbox:bookworm-slim dùng Dockerfile.sandbox.
docker.networkmặc định là"none"(không egress).readOnlyRoot: truechặn việc cài gói.usermust be root forapt-get(omituseror setuser: "0:0"). OpenClaw auto-recreates containers whensetupCommand(or docker config) changes unless the container was recently used (within ~5 minutes). Hot containers log a warning with the exactopenclaw sandbox recreate ...command.
agents.defaults.sandbox.docker:
network, user, pidsLimit, memory, memorySwap, cpus, ulimits,
seccompProfile, apparmorProfile, dns, extraHosts.
Đa tác tử: ghi đè agents.defaults.sandbox.{docker,browser,prune}.* theo từng tác tử qua agents.list[].sandbox.{docker,browser,prune}.*
(bị bỏ qua khi agents.defaults.sandbox.scope / agents.list[].sandbox.scope là "shared").
Build image sandbox mặc định
Image sandbox dùng chung (tùy chọn)
Nếu bạn muốn một image sandbox có sẵn công cụ build phổ biến (Node, Go, Rust, v.v.), hãy build image dùng chung:openclaw-sandbox-common:bookworm-slim. To use it:
Image sandbox cho trình duyệt
Image trình duyệt tùy chỉnh:openclaw-sandbox-browser:bookworm-slim using
Dockerfile.sandbox-browser. The container runs Chromium with CDP enabled and
an optional noVNC observer (headful via Xvfb).
Ghi chú:
- Có giao diện (Xvfb) giúp giảm bị chặn bot so với headless.
- Headless vẫn có thể dùng bằng cách đặt
agents.defaults.sandbox.browser.headless=true. - Không cần môi trường desktop đầy đủ (GNOME); Xvfb cung cấp hiển thị.
denyđược ưu tiên hơnallow.- Nếu
allowtrống: tất cả công cụ (trừ deny) đều khả dụng.
browser (and remove it from
deny) or the tool remains blocked.
Prune rules (agents.defaults.sandbox.prune) apply to browser containers too.
Image sandbox tùy chỉnh
Build image của riêng bạn và trỏ cấu hình tới nó:Ghi chú bảo mật
- Hàng rào cứng chỉ áp dụng cho công cụ (exec/read/write/edit/apply_patch).
- Công cụ chỉ chạy trên host như browser/camera/canvas bị chặn theo mặc định.
- Cho phép
browsertrong sandbox phá vỡ cô lập (trình duyệt chạy trên host).
Xử lý sự cố
Hai nút:prune.idleHours: xóa container không dùng trong X giờ (0 = tắt)prune.maxAgeDays: xóa container cũ hơn X ngày (0 = tắt)
- Giữ các phiên bận rộn nhưng giới hạn tuổi thọ:
idleHours: 24,maxAgeDays: 7 - Không bao giờ dọn dẹp:
idleHours: 0,maxAgeDays: 0
Ghi chú bảo mật
- Hàng rào cứng chỉ áp dụng cho công cụ (exec/read/write/edit/apply_patch).
- Công cụ chỉ chạy trên host như browser/camera/canvas bị chặn theo mặc định.
- Cho phép
browsertrong sandbox phá vỡ cô lập (trình duyệt chạy trên host).
Xử lý sự cố
- Thiếu image: build bằng
scripts/sandbox-setup.shhoặc đặtagents.defaults.sandbox.docker.image. - Container không chạy: nó sẽ tự tạo theo phiên khi cần.
- Lỗi quyền trong sandbox: đặt
docker.userthành UID:GID khớp với quyền sở hữu workspace được mount (hoặc chown thư mục workspace). - Custom tools not found: OpenClaw runs commands with
sh -lc(login shell), which sources/etc/profileand may reset PATH. Setdocker.env.PATHto prepend your custom tool paths (e.g.,/custom/bin:/usr/local/share/npm-global/bin), or add a script under/etc/profile.d/in your Dockerfile.