openclaw默认沿用openhands的config.toml配置机制,需挂载自定义config.toml至/.openhands/config.toml路径,其中[llm]段必须包含model和api_key字段,容器启动时自动加载该配置作为默认模型。
☞☞☞AI 智能聊天, 问答助手, AI 智能搜索, 多模态理解力帮你轻松跨越从0到1的创作门槛☜☜☜

你想在 OpenClaw 的 Docker 部署中让 AI 一启动就用你指定的模型,而不是每次手动选、或者卡在未配置状态进不了主界面——这需要在容器启动前就写死模型配置,否则 Web UI 初始化时会因缺少有效 LLM 配置而阻塞或报错。
确认 OpenClaw 是否使用 OpenHands 架构
OpenClaw 是基于 OpenHands 框架构建的衍生项目,其 Docker 镜像、配置结构和模型加载逻辑与 OpenHands 高度一致。当前(2026年7月)主流 OpenClaw 镜像(如 openclaw/openclaw:latest)默认沿用 OpenHands 的 config.toml 模型配置机制,而非环境变量注入方式。若强行用 LLM_MODEL_NAME 等环境变量覆盖,将被忽略。
准备自定义 config.toml 文件
新建一个本地文件 config.toml,内容必须包含完整 LLM 配置段,且至少含 model 和 api_key 两项:
[llm]
model = "claude-3-5-sonnet-20240620"
base_url = "https://api.anthropic.com/v1"
api_key = "sk-ant-api03-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
temperature = 0.1
【注意:model 字段值必须与你所用 API 服务商实际支持的模型名完全一致,大小写、连字符、版本号都不能错;填错会导致容器启动后立即报 404 或 401 错误,且 UI 不会提示具体原因】
挂载 config.toml 到容器内固定路径
Docker 启动时,通过 -v 将你本地的 config.toml 映射到容器内 /.openhands/config.toml:
docker run -itd \
--rm \
--pull=always \
-e LOG_ALL_EVENTS=true \
-v $(pwd)/config.toml:/.openhands/config.toml \
-v ./workspace:/workspace \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ./.openhands:/.openhands \
 -p 3000:3000 \
--add-host host.docker.internal:host-gateway \
--name openclaw-test \
openclaw/openclaw:latest
这一步是关键:OpenClaw 容器启动时会主动读取 /.openhands/config.toml,若存在则跳过初始化引导页,直接加载该配置作为默认模型。
验证默认模型是否生效
容器启动后,打开 http://localhost:3000 → 进入任务创建页 → 点击「Agent Settings」→ 查看「Model」下拉框:
如果显示为你 config.toml 中写的 claude-3-5-sonnet-20240620(或你填的其他模型名),且右侧有绿色对勾图标,说明配置已生效;【若仍显示 “Select a model” 或为空,则说明 config.toml 路径挂载错误,或文件权限为只读,或 model 字段格式非法】










