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.sh

setup.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宿主机 URLDocker 配置 URL
LM Studiohttp://127.0.0.1:1234http://host.docker.internal:1234
Ollamahttp://127.0.0.1:11434http://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

相关链接