Please enable Javascript to view the contents

容器化部署 OpenClaw

 ·  ☕ 2 分钟

1. 启动容器

  • 设置镜像
1
export IMAGE=ghcr.io/openclaw/openclaw:2026.3.2
  • 生成随机 token
1
openssl rand -hex 32
  • 设置网关 token
1
export OPENCLAW_GATEWAY_TOKEN=cae189bbe7fd258e1cd3bd55e1fb952253cc3fe98abd39c292477a1e25336ef8 

这个 token 会用于远程 Web 端,本地 Tui 端的认证。

  • 设置目录权限
1
2
mkdir -p openclaw-home
chmod -R 777 openclaw-home
  • 启动容器
1
2
3
4
5
6
7
nerdctl run -d --user root \
  --name openclaw \
  --restart always \
  -p 18789:18789 \
  -v $(pwd)/openclaw-home:/root/ \
  $IMAGE \
  sleep infinity
  • 删除容器
1
nerdctl rm openclaw --force

2. 启动服务

  • 创建配置文件
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
cat <<EOF > openclaw-home/.openclaw/openclaw.json
{
  "models": {
    "mode": "merge",
    "providers": {
      "custom": {
        "baseUrl": "https://x.x.x.x/v1",
        "apiKey": "x.x.x.x",
        "api": "openai-completions",
        "models": [
          {
            "id": "default",
            "name": "default",
            "reasoning": false,
            "input": [
              "text"
            ],
            "cost": {
              "input": 0,
              "output": 0,
              "cacheRead": 0,
              "cacheWrite": 0
            },
            "contextWindow": 262144,
            "maxTokens": 262144
          }
        ]
      }
    }
  },
  "agents": {
    "defaults": {
      "model": {
        "primary": "custom/qwen3.5-plus"
      },
      "models": {
        "custom/qwen3.5-plus": {},
      },
      "workspace": "/root/.openclaw/workspace",
      "compaction": {
        "mode": "safeguard"
      },
      "timeoutSeconds": 120,
      "maxConcurrent": 4,
      "subagents": {
        "maxConcurrent": 8
      }
    },
    "list": [
      {
        "id": "main"
      }
    ]
  },
  "tools": {
  },
  "messages": {
    "ackReactionScope": "group-mentions"
  },
  "gateway": {
    "port": 18789,
    "mode": "local",
    "bind": "lan",
    "controlUi": {
      "enabled": true,
      "basePath": "/openclaw",
      "allowInsecureAuth": true,
      "allowedOrigins": [ "*" ]
    },
    "auth": {
      "mode": "token",
      "token": "$OPENCLAW_GATEWAY_TOKEN"
    }
  }
}
EOF

这里将 bind 设置为 lan 用于远端访问,同时将 basepath 设置为 /openclaw 便于 Web 路由配置。

  • 进入容器
1
nerdctl exec -it openclaw bash
  • 启动服务
1
node openclaw.mjs gateway

3. 使用

3.1 本地

1
2
nerdctl exec -it openclaw \
  node openclaw.mjs agent --agent main --message "介绍一下你自己吧"

3.2 Web 端

打开地址 http://${HOST_IP}:18789/openclaw 即可看到 Web 端。

但配置 token 之后,还需授权设备才能使用。

  • 查看设备列表
1
node openclaw.mjs devices list
1
2
3
4
5
6
7
8
Pending (1)
┌──────────────────────────────────────┬────────────────────────┬──────────┬────────────┬──────────┬────────┐
│ Request                              │ Device                 │ Role     │ IP         │ Age      │ Flags  │
├──────────────────────────────────────┼────────────────────────┼──────────┼────────────┼──────────┼────────┤
│ 83730280-7fa9-4576-bd34-30733275b8f6 │ ff3db6b1cf6fbef9a33222 │ operator │            │ just now │        │
│                                      │ 3912cc3cf7ea5a3af03dea │          │            │          │        │
│                                      │ 333a96c622566617936f   │          │            │          │        │
└──────────────────────────────────────┴────────────────────────┴──────────┴────────────┴──────────┴────────┘
  • 授权设备
1
node openclaw.mjs devices approve 83730280-7fa9-4576-bd34-30733275b8f6

微信公众号
作者
微信公众号