OpenClaw Docker 部署指南

本文档详细介绍如何使用 Docker 部署 OpenClaw 汉化版,包括一键部署、本地快速启动、服务器远程部署等多种方式。

一键部署脚本(推荐)

自动完成初始化、配置远程访问、启动容器:

Linux / macOS:

curl -fsSL https://cdn.jsdelivr.net/gh/1186258278/OpenClawChineseTranslation@main/docker-deploy.sh | bash

Windows PowerShell:

irm https://cdn.jsdelivr.net/gh/1186258278/OpenClawChineseTranslation@main/docker-deploy.ps1 | iex

镜像地址

镜像源 地址 适用场景
Docker Hub 1186258278/openclaw-zh 国内用户推荐,速度快
ghcr.io ghcr.io/1186258278/openclaw-zh 海外用户 / 默认

以下命令默认使用 ghcr.io 地址。国内用户将 ghcr.io/1186258278/openclaw-zh 替换为 1186258278/openclaw-zh 即可加速。

本地快速启动

适用于在本机运行并通过 localhost 访问:

镜像地址(国内用户推荐使用 Docker Hub 加速):

# 海外: ghcr.io/1186258278/openclaw-zh:latest
# 国内: 1186258278/openclaw-zh:latest
IMAGE=ghcr.io/1186258278/openclaw-zh:latest

1. 初始化配置(首次运行,需要交互式配置 AI 模型和 API 密钥):

# Linux/macOS:
docker run --rm -it -v openclaw-data:/root/.openclaw \
  $IMAGE openclaw onboard

# Windows (PowerShell):
docker run --rm -it -v openclaw-data:/root/.openclaw `
  $IMAGE openclaw onboard

2. 配置网关模式(本地访问):

# Linux/macOS:
docker run --rm -v openclaw-data:/root/.openclaw \
  $IMAGE openclaw config set gateway.mode local

# Windows (PowerShell):
docker run --rm -v openclaw-data:/root/.openclaw `
  $IMAGE openclaw config set gateway.mode local

3. 启动容器(守护进程模式,容器会一直运行):

# Linux/macOS:
docker run -d \
  --name openclaw \
  -p 18789:18789 \
  -v openclaw-data:/root/.openclaw \
  --restart unless-stopped \
  $IMAGE \
  openclaw gateway run

# Windows (PowerShell):
docker run -d --name openclaw -p 18789:18789 -v openclaw-data:/root/.openclaw --restart unless-stopped $IMAGE openclaw gateway run

访问:http://localhost:18789

服务器远程部署

部署到服务器并从其他设备访问时,需要额外配置:

1. 创建数据卷:

docker volume create openclaw-data

2. 初始化配置(首次运行,需要交互式配置 AI 模型和 API 密钥):

# Linux/macOS:
docker run --rm -it -v openclaw-data:/root/.openclaw \
  $IMAGE openclaw onboard

# Windows (PowerShell):
docker run --rm -it -v openclaw-data:/root/.openclaw `
  $IMAGE openclaw onboard

3. 配置远程访问参数:

# Linux/macOS:
docker run --rm -v openclaw-data:/root/.openclaw \
  $IMAGE openclaw config set gateway.mode local
docker run --rm -v openclaw-data:/root/.openclaw \
  $IMAGE openclaw config set gateway.bind lan

# Windows (PowerShell):
docker run --rm -v openclaw-data:/root/.openclaw `
  $IMAGE openclaw config set gateway.mode local
docker run --rm -v openclaw-data:/root/.openclaw `
  $IMAGE openclaw config set gateway.bind lan

4. 设置访问令牌(推荐):

# Linux/macOS:
docker run --rm -v openclaw-data:/root/.openclaw \
  $IMAGE openclaw config set gateway.auth.token your-secure-token

# Windows (PowerShell):
docker run --rm -v openclaw-data:/root/.openclaw `
  $IMAGE openclaw config set gateway.auth.token your-secure-token

5. 启动容器(守护进程模式,容器会一直运行):

# Linux/macOS:
docker run -d \
  --name openclaw \
  -p 18789:18789 \
  -v openclaw-data:/root/.openclaw \
  --restart unless-stopped \
  $IMAGE \
  openclaw gateway run

# Windows (PowerShell):
docker run -d --name openclaw -p 18789:18789 -v openclaw-data:/root/.openclaw --restart unless-stopped $IMAGE openclaw gateway run

访问:http://服务器IP:18789 → 在 Dashboard 输入 token 连接

远程访问与 Token 认证

通过 HTTP 从非 localhost 访问时,浏览器会阻止设备身份验证(Web Crypto API 需要 secure context)。

推荐解决方案:设置 Token 认证

# 1. 设置访问令牌
docker exec openclaw openclaw config set gateway.auth.token YOUR_TOKEN
docker restart openclaw

# 2. 在浏览器访问远程地址
http://服务器IP:18789/overview

# 3. 在「网关令牌」输入框填入 YOUR_TOKEN,点击「连接」

设置 gateway.auth.token 后,即使通过远程 HTTP 访问,只要在 Dashboard 输入正确的 token 就能连接成功。