部署教程 较易 15-30分钟

本地电脑部署 OpenClaw

在你的 Windows/Mac/Linux 电脑上部署 OpenClaw,适合个人使用和学习

#Local Deploy #Docker #Beginner

准备工作

  • A computer (Windows/Mac/Linux)
  • At least 4GB available memory (8GB recommended)
  • Stable internet connection
  • Node.js 22+ (if using npm installation)

操作步骤

1

安装 Docker Desktop

Docker 是一个打包工具,让 OpenClaw 可以在任何系统上运行。

命令 / 操作

Windows/Mac
下载并安装 Docker Desktop: https://www.docker.com/products/docker-desktop
Linux
curl -fsSL https://get.docker.com | sh

小提示

  • Restart computer after installation
  • Ensure Docker Desktop is running (whale icon in system tray)
  • Windows users strongly recommended to use WSL2
2

macOS 额外准备

macOS 用户需要先安装 Xcode Command Line Tools。

命令 / 操作

macOS
xcode-select --install

小提示

  • If already installed, it will show 'already installed'
  • This enables AppleScript capabilities (needed for iMessage, Apple Notes skills)
3

准备配置文件

创建一个文件夹存放 OpenClaw 的配置和数据。

命令 / 操作

Mac/Linux
mkdir -p ~/openclaw && cd ~/openclaw
Windows (PowerShell)
mkdir C:\openclaw && cd C:\openclaw

小提示

  • This folder will store your config and chat history
  • Recommended to place in user home directory for easy management
4

拉取 OpenClaw 镜像

从 Docker Hub 下载 OpenClaw 镜像。

命令 / 操作

All Systems
docker pull openclaw/openclaw:latest

小提示

  • Image size is about 1-2GB, first download takes a few minutes
  • Ensure stable network, configure Docker mirror accelerator if slow
5

运行 OpenClaw 容器

使用 Docker 启动 OpenClaw 服务,并挂载数据目录。

命令 / 操作

Mac/Linux
docker run -d --name openclaw -p 18789:18789 -p 3000:3000 -v ~/openclaw/.openclaw:/root/.openclaw -v ~/openclaw/workspace:/workspace openclaw/openclaw:latest
Windows (PowerShell)
docker run -d --name openclaw -p 18789:18789 -p 3000:3000 -v C:\openclaw\.openclaw:/root/.openclaw -v C:\openclaw\workspace:/workspace openclaw/openclaw:latest

小提示

  • Important: Must mount both directories, or config and chat history will be lost on restart
  • ~/.openclaw stores runtime state, workspace stores YAML config files
  • 18789 is Gateway WebSocket port, 3000 is Web UI port
6

等待服务启动

OpenClaw 首次启动需要初始化,请耐心等待。

命令 / 操作

All Systems
docker logs -f openclaw

小提示

  • Seeing 'Gateway started' or similar log means startup successful
  • Press Ctrl+C to exit log view (won't stop the service)
  • First startup may take 1-2 minutes
7

访问 Web 界面

打开浏览器访问 OpenClaw 管理界面。

命令 / 操作

All Systems
打开浏览器,访问 http://localhost:3000

小提示

  • First access requires setting admin password
  • If can't access, wait 30 seconds and retry
  • If port is occupied, modify port in run command
8

初始化配置(Onboard)

完成首次配置,包括选择模型、配置 API Key、设置消息频道等。

命令 / 操作

All Systems
在管理界面点击「设置」→「模型配置」→「添加模型」

小提示

  • Google Gemini is recommended for beginners (has free quota)
  • Claude, GPT-4, DeepSeek are also available
  • See FAQ below for how to get API Key
9

安装守护进程(可选)

让 OpenClaw 在后台持续运行,即使关闭终端也不会中断。

命令 / 操作

All Systems
Docker 容器已自带后台运行能力,无需额外配置

小提示

  • Docker's --restart always ensures auto-start: docker update --restart always openclaw
  • Mac users: run 'caffeinate -i' to prevent sleep disconnect
  • Linux servers: recommend using systemd for management

常见问题

端口被占用怎么办?
修改命令中的端口号,如 `-p 3001:3000 -p 18790:18789`,然后访问 http://localhost:3001
Docker 启动失败?
确保 Docker Desktop 正在运行,并检查是否有足够的内存(建议 4GB+)。运行 docker logs openclaw 查看错误日志
容器重启后配置丢失?
确保使用了 -v 参数挂载数据目录。如果没有,需要重新配置。建议删除容器后重新创建并正确挂载目录
Mac 电脑休眠后断联?
在终端运行 caffeinate -i 防止休眠断联。或者考虑部署到云服务器实现 7×24 运行
如何查看运行日志?
运行 docker logs -f openclaw 查看实时日志,按 Ctrl+C 退出
如何更新到最新版本?
运行 docker pull openclaw/openclaw:latest 拉取最新镜像,然后 docker rm -f openclaw 删除旧容器,重新运行启动命令
Windows 直接运行有问题?
强烈推荐使用 WSL2(Windows Subsystem for Linux)运行。直接在 Windows 原生环境可能遇到路径、权限等兼容性问题