使用Docker安装OpenClaw

1、安装Docker

合集:Docker安装与使用

2、安装OpenClaw

bash 复制代码
详见:https://docs.openclaw.ai/zh-CN/install/docker

创建目录:

bash 复制代码
mkdir openclaw

切换目录:

bash 复制代码
cd openclaw

下载docker-compose.yml文件:

bash 复制代码
详见:https://github.com/openclaw/openclaw/blob/main/docker-compose.yml
bash 复制代码
# 方式1:
wget https://raw.githubusercontent.com/openclaw/openclaw/main/docker-compose.yml


# 方式2:使用代理下载
# 详见:https://mp.weixin.qq.com/s/XTbT3wKp_W2fiK7pGpo7Qg
wget https://gh-proxy.com/https://raw.githubusercontent.com/openclaw/openclaw/main/docker-compose.yml

查看docker-compose.yml文件:

bash 复制代码
services:
  openclaw-gateway:
    image: ${OPENCLAW_IMAGE:-openclaw:local}
    environment:
      HOME: /home/node
      TERM: xterm-256color
      OPENCLAW_GATEWAY_TOKEN: ${OPENCLAW_GATEWAY_TOKEN:-}
      OPENCLAW_ALLOW_INSECURE_PRIVATE_WS: ${OPENCLAW_ALLOW_INSECURE_PRIVATE_WS:-}
      CLAUDE_AI_SESSION_KEY: ${CLAUDE_AI_SESSION_KEY:-}
      CLAUDE_WEB_SESSION_KEY: ${CLAUDE_WEB_SESSION_KEY:-}
      CLAUDE_WEB_COOKIE: ${CLAUDE_WEB_COOKIE:-}
    volumes:
      - ${OPENCLAW_CONFIG_DIR}:/home/node/.openclaw
      - ${OPENCLAW_WORKSPACE_DIR}:/home/node/.openclaw/workspace
      ## Uncomment the lines below to enable sandbox isolation
      ## (agents.defaults.sandbox). Requires Docker CLI in the image
      ## (build with --build-arg OPENCLAW_INSTALL_DOCKER_CLI=1) or use
      ## docker-setup.sh with OPENCLAW_SANDBOX=1 for automated setup.
      ## Set DOCKER_GID to the host's docker group GID (run: stat -c '%g' /var/run/docker.sock).
      # - /var/run/docker.sock:/var/run/docker.sock
    # group_add:
    #   - "${DOCKER_GID:-999}"
    ports:
      - "${OPENCLAW_GATEWAY_PORT:-18789}:18789"
      - "${OPENCLAW_BRIDGE_PORT:-18790}:18790"
    init: true
    restart: unless-stopped
    command:
      [
        "node",
        "dist/index.js",
        "gateway",
        "--bind",
        "${OPENCLAW_GATEWAY_BIND:-lan}",
        "--port",
        "18789",
      ]
    healthcheck:
      test:
        [
          "CMD",
          "node",
          "-e",
          "fetch('http://127.0.0.1:18789/healthz').then((r)=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))",
        ]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 20s

  openclaw-cli:
    image: ${OPENCLAW_IMAGE:-openclaw:local}
    network_mode: "service:openclaw-gateway"
    cap_drop:
      - NET_RAW
      - NET_ADMIN
    security_opt:
      - no-new-privileges:true
    environment:
      HOME: /home/node
      TERM: xterm-256color
      OPENCLAW_GATEWAY_TOKEN: ${OPENCLAW_GATEWAY_TOKEN:-}
      OPENCLAW_ALLOW_INSECURE_PRIVATE_WS: ${OPENCLAW_ALLOW_INSECURE_PRIVATE_WS:-}
      BROWSER: echo
      CLAUDE_AI_SESSION_KEY: ${CLAUDE_AI_SESSION_KEY:-}
      CLAUDE_WEB_SESSION_KEY: ${CLAUDE_WEB_SESSION_KEY:-}
      CLAUDE_WEB_COOKIE: ${CLAUDE_WEB_COOKIE:-}
    volumes:
      - ${OPENCLAW_CONFIG_DIR}:/home/node/.openclaw
      - ${OPENCLAW_WORKSPACE_DIR}:/home/node/.openclaw/workspace
    stdin_open: true
    tty: true
    init: true
    entrypoint: ["node", "dist/index.js"]
    depends_on:
      - openclaw-gateway

下载.env.example文件:

bash 复制代码
详见:https://github.com/openclaw/openclaw/blob/main/.env.example
bash 复制代码
# 方式1:
wget https://raw.githubusercontent.com/openclaw/openclaw/main/.env.example

# 方式2:使用代理下载
# 详见:https://mp.weixin.qq.com/s/XTbT3wKp_W2fiK7pGpo7Qg
wget https://gh-proxy.com/https://raw.githubusercontent.com/openclaw/openclaw/main/.env.example

查看.env.example文件:

bash 复制代码
# OpenClaw .env example
#
# Quick start:
# 1) Copy this file to `.env` (for local runs from this repo), OR to `~/.openclaw/.env` (for launchd/systemd daemons).
# 2) Fill only the values you use.
# 3) Keep real secrets out of git.
#
# Env-source precedence for environment variables (highest -> lowest):
# process env, ./.env, ~/.openclaw/.env, then openclaw.json `env` block.
# Existing non-empty process env vars are not overridden by dotenv/config env loading.
# Note: direct config keys (for example `gateway.auth.token` or channel tokens in openclaw.json)
# are resolved separately from env loading and often take precedence over env fallbacks.

# -----------------------------------------------------------------------------
# Gateway auth + paths
# -----------------------------------------------------------------------------
# Recommended if the gateway binds beyond loopback.
OPENCLAW_GATEWAY_TOKEN=change-me-to-a-long-random-token
# Example generator: openssl rand -hex 32

# Optional alternative auth mode (use token OR password).
# OPENCLAW_GATEWAY_PASSWORD=change-me-to-a-strong-password

# Optional path overrides (defaults shown for reference).
# OPENCLAW_STATE_DIR=~/.openclaw
# OPENCLAW_CONFIG_PATH=~/.openclaw/openclaw.json
# OPENCLAW_HOME=~

# Optional: import missing keys from your login shell profile.
# OPENCLAW_LOAD_SHELL_ENV=1
# OPENCLAW_SHELL_ENV_TIMEOUT_MS=15000

# -----------------------------------------------------------------------------
# Model provider API keys (set at least one)
# -----------------------------------------------------------------------------
# OPENAI_API_KEY=sk-...
# ANTHROPIC_API_KEY=sk-ant-...
# GEMINI_API_KEY=...
# OPENROUTER_API_KEY=sk-or-...
# OPENCLAW_LIVE_OPENAI_KEY=sk-...
# OPENCLAW_LIVE_ANTHROPIC_KEY=sk-ant-...
# OPENCLAW_LIVE_GEMINI_KEY=...
# OPENAI_API_KEY_1=...
# ANTHROPIC_API_KEY_1=...
# GEMINI_API_KEY_1=...
# GOOGLE_API_KEY=...
# OPENAI_API_KEYS=sk-1,sk-2
# ANTHROPIC_API_KEYS=sk-ant-1,sk-ant-2
# GEMINI_API_KEYS=key-1,key-2

# Optional additional providers
# ZAI_API_KEY=...
# AI_GATEWAY_API_KEY=...
# MINIMAX_API_KEY=...
# SYNTHETIC_API_KEY=...

# -----------------------------------------------------------------------------
# Channels (only set what you enable)
# -----------------------------------------------------------------------------
# TELEGRAM_BOT_TOKEN=123456:ABCDEF...
# DISCORD_BOT_TOKEN=...
# SLACK_BOT_TOKEN=xoxb-...
# SLACK_APP_TOKEN=xapp-...

# Optional channel env fallbacks
# MATTERMOST_BOT_TOKEN=...
# MATTERMOST_URL=https://chat.example.com
# ZALO_BOT_TOKEN=...
# OPENCLAW_TWITCH_ACCESS_TOKEN=oauth:...

# -----------------------------------------------------------------------------
# Tools + voice/media (optional)
# -----------------------------------------------------------------------------
# BRAVE_API_KEY=...
# PERPLEXITY_API_KEY=pplx-...
# FIRECRAWL_API_KEY=...

# ELEVENLABS_API_KEY=...
# XI_API_KEY=...  # alias for ElevenLabs
# DEEPGRAM_API_KEY=...

复制.env.example文件:

bash 复制代码
cp .env.example .env

修改.env文件:

bash 复制代码
# 修改token/令牌:
sed -i "s/OPENCLAW_GATEWAY_TOKEN=change-me-to-a-long-random-token/OPENCLAW_GATEWAY_TOKEN=$(openssl rand -hex 32)/g" .env

# 修改配置文件所在目录:
echo "" >> .env
echo "OPENCLAW_CONFIG_DIR=./config" >> .env
echo "OPENCLAW_WORKSPACE_DIR=./config/workspace" >> .env

# 修改镜像:
echo "" >> .env
echo "OPENCLAW_IMAGE=ghcr.nju.edu.cn/openclaw/openclaw:latest" >> .env

查看token/网关令牌:

bash 复制代码
cat .env | grep OPENCLAW_GATEWAY_TOKEN

创建目录并添加权限:

bash 复制代码
详见:
https://docs.openclaw.ai/zh-CN/install/docker#权限-+-eacces
https://github.com/openclaw/openclaw/issues/21571
https://github.com/openclaw/openclaw/issues/27336
https://coclaw.com/troubleshooting/solutions/docker-eacces-openclaw-config-dir
bash 复制代码
# 1、创建目录
mkdir -p ./config/workspace

# 2、添加配置
cat << EOF > config/openclaw.json
{
  "gateway": {
    "mode": "local",
    "bind": "lan",
    "port": 18789,
    "controlUi": {
      "dangerouslyAllowHostHeaderOriginFallback": true,
      "allowInsecureAuth": true,
      "dangerouslyDisableDeviceAuth": true
    }
  }
}
EOF

# 3、修改组、添加权限
chown -R 1000:1000 ./config
#chmod -R 777 ./config

创建并启动容器:

复制代码
docker-compose up -d

查看容器列表:

复制代码
docker ps

停止并销毁容器:

复制代码
docker-compose down

删除目录:

复制代码
rm -rf ./config

删除镜像:

bash 复制代码
docker rmi ghcr.nju.edu.cn/openclaw/openclaw:latest

3、浏览器访问

bash 复制代码
假设当前ip为192.168.186.128
浏览器访问:http://192.168.186.128:18789

首页:

点击Overview/概览:

bash 复制代码
填写"Gateway Token" 或 "网关令牌"
选择"Language" 或 "语言"
bash 复制代码
点击"Connect" 或 "连接"

4、模型提供商

bash 复制代码
当前选用"Qwen"

Qwen 为 Qwen Coder 和 Qwen Vision 模型提供免费层 OAuth 流程(每天 2,000 次请求,受 Qwen 速率限制约束)。
bash 复制代码
详见:

# openclaw.ai
https://docs.openclaw.ai/zh-CN/providers
https://docs.openclaw.ai/zh-CN/concepts/model-providers#qwen-oauth(免费层级)
https://docs.openclaw.ai/zh-CN/providers/qwen

# qwen.ai
https://qwen.ai
https://qwen.ai/qwencode
https://qwenlm.github.io/qwen-code-docs/zh/users/overview

查看容器列表:

bash 复制代码
docker ps --format "{{.ID}} {{.Image}}  {{.Names}}"

启用插件:

bash 复制代码
# 命令格式:docker exec -it 容器名称 命令

docker exec -it openclaw-openclaw-gateway-1 openclaw plugins enable qwen-portal-auth

认证:

bash 复制代码
# 命令格式:docker exec -it 容器名称 命令

docker exec -it openclaw-openclaw-gateway-1 openclaw models auth login --provider qwen-portal --set-default

浏览器访问:

bash 复制代码
访问地址格式如下:
https://chat.qwen.ai/authorize?user_code={USER_CODE}&client=qwen-code
bash 复制代码
如果没有注册,请先注册,否则,请登录。

查看代理:

聊天:

5、详见

bash 复制代码
https://openclaw.ai
https://docs.openclaw.ai/getting-started
https://docs.openclaw.ai/zh-CN
https://github.com/openclaw/openclaw
https://clawhub.ai
相关推荐
AI服务老曹15 小时前
深度解析:基于 Docker 与 GB28181 的异构计算 AI 视频管理架构,如何实现 X86/ARM 与 GPU/NPU 的全场景兼容?
运维·docker·容器
Elastic 中国社区官方博客16 小时前
使用 Elastic Observability 和 MCP 的 Agentic 驱动 Kubernetes 调查
数据库·elasticsearch·搜索引擎·云原生·容器·kubernetes·全文检索
阿正的梦工坊16 小时前
DOCKER_DATABASE_URL 逐段解析:部署时候的信息解析
数据库·docker·容器
ifeng031016 小时前
基于OpenClaw自动化-自动制作视频并发布到草稿箱
openclaw
郝开16 小时前
Docker Compose 本地环境搭建:nacos
运维·docker·容器
终端行者16 小时前
Jenkins Pipeline在不同阶段指定不同的 agent 或 Docker 容器进行执行任务和固定一个节点分段执行任务,一文带你搞定
java·docker·jenkins·cicd
旷世奇才李先生16 小时前
Docker\+K8s的核心价值与应用场景
docker·容器·kubernetes
梵得儿SHI16 小时前
SpringCloud 生产级落地:Docker 容器化 + K8s 编排部署全攻略(含完整 yaml + 避坑指南)
docker·云原生·kubernetes·k8s·springcloud·微服务部署·java 后端
jinanwuhuaguo16 小时前
OpenClaw范式深度剖析:从技术突破到安全治理的系统性研究(第二篇)
开发语言·人工智能·安全·架构·kotlin·openclaw
Suhan4216 小时前
新版本Docker Desktop 自定义安装路径和下载镜像地址路径修改(附must be owned by an elevated account问题解决)
运维·docker·容器·eureka