容器内升级openclaw

docker run -u root 进入你的openclaw容器(不带-u默认node用户)

# 1. 强制安装最新版并覆盖旧链接
npm install -g openclaw@latest --force --registry=https://registry.npmmirror.com

# 2. 建立目录软链接(将 npm 全局路径映射到 app 工作目录)
rm -rf /app/dist /app/node_modules
ln -sf /usr/local/lib/node_modules/openclaw/dist /app/dist
ln -sf /usr/local/lib/node_modules/openclaw/node_modules /app/node_modules

# 3. 清理旧版模型缓存(激活 128k 规格的关键)
rm -f /root/.openclaw/models.json

# 4. 权限归属与启动
chown -R node:node /root/.openclaw
exec node /app/dist/index.js gateway

npm install升级openclaw gateway,但web ui前端文件不会主动引导到新的目录/usr/local/lib/node_modules/openclaw/dist,所以即使openclaw --version看到已经完成升级,但web ui显示还是旧版本,此处将新版本目录覆盖旧版本目录即可

遇到的问题

报错说明解决
Missing config. Run openclaw setup or set gateway.mode=local (or pass --allow-unconfigured).出现类似配置文件已配置但读不到,需要注意检查当前用户,启动命令会在当前用户目录下.openclaw找json切换到对应用户
npm error code EEXIST、npm error path /usr/local/bin/openclaw、npm error EEXIST: file already existsopenclaw二进制文件已存在无直接覆盖npm install -g openclaw@latest 加上 --force
如果你只想本地访问bind 的值lan改成 loopback

重建openclaw

若出现openclaw误操作起不来,可使用如下启动命令重建新版本的openclaw(官方docker-setup.sh拉起的镜像openclaw:local)

docker run -d \
  --name openclaw-prod \
  --restart unless-stopped \
  -u root \
  --memory=8g \
  -p 18789:18789 \
  -p 18790:18790 \
  -v /root/.openclaw:/root/.openclaw \
  -v /root/.openclaw/workspace:/root/.openclaw/workspace \
  -e NODE_ENV=production \
  -e NODE_OPTIONS="--max-old-space-size=4096" \
  --entrypoint "/bin/sh" \
  openclaw:local \
  -c "npm install -g openclaw@latest --force --registry=https://registry.npmmirror.com && \
      rm -rf /app/dist /app/node_modules && \
      ln -sf /usr/local/lib/node_modules/openclaw/dist /app/dist && \
      ln -sf /usr/local/lib/node_modules/openclaw/node_modules /app/node_modules && \
      exec node /app/dist/index.js gateway"

参考openclaw.json (gateway部分)

  "gateway": {
    "port": 18789,
    "mode": "local",
    "bind": "lan",
    "controlUi": {
      "enabled": true,
      "allowedOrigins": [
        "http://物理机ip:18789",
        "http://127.0.0.1:18789",
        "http://localhost:18789"
      ],
      "dangerouslyAllowHostHeaderOriginFallback": true,
      "allowInsecureAuth": true,
      "dangerouslyDisableDeviceAuth": true
    },
    "auth": {
      "mode": "token",
      "token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"   #gateway授权token
    },
    "trustedProxies": [
      "192.168.65.0/24",
      "172.18.0.0/16"
    ],
    "tailscale": {
      "mode": "off",
      "resetOnExit": false
    },
    "nodes": {
      "denyCommands": [
        "camera.snap",
        "camera.clip",
        "screen.record",
        "contacts.add",
        "calendar.add",
        "reminders.add",
        "sms.send"
      ]
    }
  },

openclaw.json工具与安全策略部分

  "tools": {
    "profile": "coding",
    "exec": {
      "host": "gateway",
      "security": "full",
      "ask": "on-miss"
    }
  },
Logo

小龙虾开发者社区是 CSDN 旗下专注 OpenClaw 生态的官方阵地,聚焦技能开发、插件实践与部署教程,为开发者提供可直接落地的方案、工具与交流平台,助力高效构建与落地 AI 应用

更多推荐