Rebuild openclaw from npm instead of premade image, configure Ollama

- Add Dockerfile using node:22-bookworm-slim + npm install -g openclaw@latest
- Update docker-compose.yml: use local build, add OLLAMA_API_KEY=ollama-local,
  remove legacy OPENCLAW_AGENT_PROVIDER/MODEL/OLLAMA_BASE_URL env vars
- Add setup.sh to create openclaw.json with explicit Ollama provider config

Key fixes vs previous attempt:
- Config file is openclaw.json (not config.json or auth-profiles.json)
- models.providers.ollama needs baseUrl with /v1 suffix + explicit model list
- OLLAMA_API_KEY env var is required to opt in to Ollama support
- reasoning:false on models prevents 400 errors from Ollama
This commit is contained in:
2026-02-20 22:03:43 +00:00
parent e9bf43469c
commit 18b202909c
3 changed files with 102 additions and 13 deletions
+17
View File
@@ -0,0 +1,17 @@
FROM node:22-bookworm-slim
# Install git and ca-certificates required by openclaw's npm dependencies
RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates && rm -rf /var/lib/apt/lists/*
# Rewrite any SSH GitHub URLs to HTTPS so npm install works without SSH keys
RUN git config --global url."https://github.com/".insteadOf "ssh://git@github.com/"
# Install openclaw from npm (same approach as the official docker-setup.sh)
RUN npm install -g openclaw@latest --loglevel=error
ENV HOME=/home/node
ENV TERM=xterm-256color
# Run as non-root node user (uid 1000), same as official image
USER node
WORKDIR /home/node
+4 -13
View File
@@ -1,25 +1,16 @@
services:
openclaw:
container_name: openclaw
image: ghcr.io/openclaw/openclaw:main
platform: linux/amd64
build: .
restart: unless-stopped
command: ["node", "openclaw.mjs", "gateway", "--allow-unconfigured", "--bind", "lan"]
command: ["openclaw", "gateway", "--allow-unconfigured", "--bind", "lan"]
environment:
- HOME=/home/node
- TERM=xterm-256color
- TZ=America/New_York
- PUID=1000
- PGID=1000
- OPENCLAW_GATEWAY_TOKEN=${OPENCLAW_GATEWAY_TOKEN}
- OPENCLAW_GATEWAY_BIND=lan
- OPENCLAW_AGENT_PROVIDER=ollama
- OPENCLAW_AGENT_MODEL=llama3
- OPENCLAW_OLLAMA_BASE_URL=http://ollama:11434
# Reverse proxy configuration
- VIRTUAL_HOST=openclaw.kolpacksoftware.com
- VIRTUAL_PORT=18789
- LETSENCRYPT_HOST=openclaw.kolpacksoftware.com
# Enable Ollama provider (opt-in via env var)
- OLLAMA_API_KEY=ollama-local
volumes:
- /srv/openclaw/config:/home/node/.openclaw
- /srv/openclaw/workspace:/home/node/.openclaw/workspace
+81
View File
@@ -0,0 +1,81 @@
#!/bin/bash
# One-time host setup for OpenClaw with Ollama
# Run this BEFORE deploying the container.
set -e
echo "=== OpenClaw + Ollama Setup ==="
echo ""
# Ensure config dirs exist
mkdir -p /srv/openclaw/config
mkdir -p /srv/openclaw/workspace
# Remove old misconfigured files from previous attempts
rm -f /srv/openclaw/config/config.json
rm -f /srv/openclaw/config/auth-profiles.json
rm -f /srv/openclaw/config/agents/main/agent/auth-profiles.json 2>/dev/null || true
# Write openclaw.json - the correct config file for provider setup
cat > /srv/openclaw/config/openclaw.json << 'EOF'
{
"models": {
"providers": {
"ollama": {
"baseUrl": "http://ollama:11434/v1",
"apiKey": "ollama-local",
"api": "openai-completions",
"models": [
{
"id": "gemma3:4b",
"name": "Gemma 3 4B",
"reasoning": false,
"input": ["text"],
"cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 },
"contextWindow": 8192,
"maxTokens": 8192
},
{
"id": "qwen2.5-coder:7b",
"name": "Qwen 2.5 Coder 7B",
"reasoning": false,
"input": ["text"],
"cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 },
"contextWindow": 8192,
"maxTokens": 8192
}
]
}
}
},
"agents": {
"defaults": {
"model": {
"primary": "ollama/gemma3:4b"
}
}
}
}
EOF
# Fix ownership so the node user (uid 1000) inside the container can read/write
chown -R 1000:1000 /srv/openclaw
echo "✓ Created /srv/openclaw/config/openclaw.json"
echo "✓ Removed old conflicting config files"
echo "✓ Fixed permissions (uid 1000)"
echo ""
echo "=== Next Steps ==="
echo ""
echo "1. Build the image:"
echo " docker compose -f openclaw/docker-compose.yml build"
echo ""
echo "2. Start the container:"
echo " docker compose -f openclaw/docker-compose.yml up -d"
echo ""
echo "3. Check logs:"
echo " docker logs openclaw -f"
echo ""
echo "4. Verify Ollama connectivity:"
echo " docker exec openclaw curl -s http://ollama:11434/v1/models | head -c 200"
echo ""
echo "5. Redeploy Portainer stack after pushing to git."