Docker 是可选的安装方式,适合需要容器化 Gateway 或隔离环境的场景。
适用场景
- 需要隔离的、可丢弃的 Gateway 环境
- 在无本地安装的主机上运行 OpenClaw
- 不适合:本机开发,直接用标准安装更快
前置条件
- Docker Desktop 或 Docker Engine + Docker Compose v2
- 至少 2 GB RAM(
pnpm install在 1 GB 主机上可能被 OOM kill) - 若在 VPS/公网主机运行,需审查 Docker
DOCKER-USER防火墙策略
快速启动
# 构建镜像(或使用预构建镜像)
export OPENCLAW_IMAGE="ghcr.io/openclaw/openclaw:latest"
./scripts/docker/setup.shsetup.sh 会自动完成 onboarding、生成 gateway token 并写入 .env,然后通过 Docker Compose 启动 Gateway。
访问 Control UI
# 打开 http://127.0.0.1:18789/,粘贴 .env 中的 token
docker compose run --rm openclaw-cli dashboard --no-open配置 Channels
# WhatsApp(扫码)
docker compose run --rm openclaw-cli channels login
# Telegram
docker compose run --rm openclaw-cli channels add --channel telegram --token "<token>"
# Discord
docker compose run --rm openclaw-cli channels add --channel discord --token "<token>"关键环境变量
| 变量 | 说明 |
|---|---|
OPENCLAW_IMAGE | 使用远程镜像而非本地构建 |
OPENCLAW_DOCKER_APT_PACKAGES | 构建时安装额外 apt 包 |
OPENCLAW_SANDBOX | 启用 sandbox(1/true) |
OPENCLAW_SKIP_ONBOARDING | 跳过交互式 onboarding |
OPENCLAW_GATEWAY_BIND | 绑定模式:lan/loopback |
本地 Provider 访问
Docker 内 127.0.0.1 指向容器本身,访问宿主机服务需用 host.docker.internal:
| Provider | 宿主机 URL | Docker 配置 URL |
|---|---|---|
| LM Studio | http://127.0.0.1:1234 | http://host.docker.internal:1234 |
| Ollama | http://127.0.0.1:11434 | http://host.docker.internal:11434 |
持久化存储
Docker Compose 将以下路径挂载到宿主机:
OPENCLAW_CONFIG_DIR→/home/node/.openclaw(含openclaw.json、auth profiles)OPENCLAW_WORKSPACE_DIR→/home/node/.openclaw/workspace
健康检查
curl -fsS http://127.0.0.1:18789/healthz # liveness
curl -fsS http://127.0.0.1:18789/readyz # readiness常见问题
- OOM(exit 137):VM 至少需要 2 GB RAM
- Unauthorized/pairing required:运行
docker compose run --rm openclaw-cli devices list并 approve - 权限错误 EACCES:确保挂载目录属主为 uid 1000
相关链接
- install-docker-vm-runtime — VM 部署共享运行时步骤
- install-clawdock — Docker 管理 shell 助手
- docs/install/install-podman — Podman 替代方案
- install-kubernetes — Kubernetes 部署