Running OpenClaw Inside Ollama's Docker Container for Simpler Networking

One r/openclaw user shared a setup that puts OpenClaw inside the same Docker container as Ollama, eliminating the need for host.docker.internal or container hostnames. The approach is straightforward: start from the official ollama/ollama image, install OpenClaw inside it, and have OpenClaw talk to Ollama on 127.0.0.1:11434. This avoids common networking friction but comes with heavy RAM usage.
Key setup steps
Launch the container with GPU support, persistent model storage, and ports 11434 and 18789 (for OpenClaw's gateway):
docker run -d \
--name ollamaopenclaw \
--gpus=all \
-v ollama_docker:/root/.ollama \
-p 11434:11434 \
-p 18789:18789 \
ollama/ollama
To bind ports only to localhost:
docker run -d \
--name ollamaopenclaw \
--gpus=all \
-v ollama_docker:/root/.ollama \
-p 127.0.0.1:11434:11434 \
-p 127.0.0.1:18789:18789 \
ollama/ollama
Open a shell in the container and install OpenClaw:
docker exec -it ollamaopenclaw sh
apt-get update && apt-get install -y curl git bash ca-certificates
curl -fsSL --proto '=https' --tlsv1.2 https://openclaw.ai/install-cli.sh | bash
export PATH="$HOME/.openclaw/bin:$PATH"
openclaw --version
Pull models (tested with small Qwen variants):
ollama pull qwen3.5:0.8b
ollama pull qwen3.5:2b
ollama pull qwen3.5:4b
ollama list
Configure OpenClaw's gateway:
export OLLAMA_API_KEY="ollama-local"
openclaw config set gateway.bind lan
openclaw config set gateway.port 18789
openclaw config set gateway.controlUi.allowedOrigins '["http://localhost:18789","http://127.0.0.1:18789"]' --strict-json
Start the gateway (keep the terminal open):
openclaw gateway run --bind lan --port 18789 --allow-unconfigured
In a second terminal, exec into the container again and run OpenClaw:
docker exec -it ollamaopenclaw sh
export PATH="$HOME/.openclaw/bin:$PATH"
export OLLAMA_API_KEY="ollama-local"
# Then run openclaw commands
Results and trade-offs
The setup works: OpenClaw uses 127.0.0.1:11434 for Ollama, no extra networking config needed. Ports and storage stay isolated. However, RAM usage is heavy—large prompts overwhelm small local models (0.8B to 4B tested). The user notes this is not a lightweight solution but is cleaner from a container isolation perspective.
Who it's for
Developers who want to run OpenClaw and Ollama in a single Docker container to avoid host networking and host.docker.internal headaches, especially for local or CI-bound LLM toolchains.
📖 Read the full source: r/openclaw
👀 See Also

Enforcing AI Agent Compliance: Bootstrap Language and Tool-Based Approaches
A developer shares practical methods for improving AI agent compliance, including using negative language in bootstraps and switching from soft rules to hard-coded tools when needed.

Helpful Tips from the OpenClaw Community: A Deep Dive into AI Agent Optimization
Discover valuable tips from the OpenClaw community on optimizing AI coding agents for better performance and efficiency. These insights could revolutionize your AI projects.

Claude Compaction Workaround: Using a Handoff.MD File
A Reddit user shares a workaround for Claude's conversation compaction message: create a detailed handoff.md file summarizing the conversation, then start a new session with that file. The post includes specific steps for using ChatGPT to generate prompts and managing projects with instructions.

Cron Jobs with AI Fallback Can Incur Unexpected API Costs When Tools Hang
A user reported that a cron job in OpenClaw checking an email inbox every 10 minutes using himalaya burned through ~$60 in API credits when the IMAP connection started hanging, triggering Claude agents on each timed-out run despite instructions to only engage AI for inbound emails.