使用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
相关推荐
七夜zippoe17 小时前
OpenClaw 内置工具详解
unity·ai·游戏引擎·openclaw·内置工具
chinesegf18 小时前
ubuntu建虚拟环境制作docker容器
linux·ubuntu·docker
Keanu-18 小时前
Docker---容器编排工具Docker Compose
docker·容器
浑水摸鱼仙君19 小时前
源码级讲述OpenClaw中的会话、记忆、上下文、系统提示词架构和原理
agent·记忆·会话·openclaw
lpfasd12319 小时前
MariaDB Docker容器权限配置问题分析与解决方案
数据库·docker·mariadb
姚不倒19 小时前
深入浅出 Kubernetes CRD、Operator 与 CR
云原生·容器·kubernetes
Tattoo_Welkin1 天前
Docker 入门
运维·docker·容器
未来转换1 天前
OpenClaw 命令大全以及使用指南
python·ai·openclaw
有毒的教程1 天前
Ubuntu 清理 Docker 镜像 / 容器 / 缓存 完整教程
ubuntu·缓存·docker
阿干tkl1 天前
openEuler 系统 Kubernetes + Harbor 学习测试环境详细部署指南
容器·kubernetes