Fix: OpenClaw in Docker — Connection Refused, Port Mapping, and Network Issues
Running OpenClaw in Docker and getting connection refused? Common issues with port mapping, bind addresses, DNS resolution, and WebSocket upgrades explained with fixes.
You start your OpenClaw gateway and hit this:
gateway failed to start: error: non-loopback control ui requires
gateway.controlui.allowedorigins (set explicit origins), or set
gateway.controlui.dangerouslyallowhostheaderoriginfallback=true
to use host-header origin fallback modeThis happens when you’re trying to access the OpenClaw Control UI from a different machine than where the gateway is running — a common scenario for VPS deployments, homelab setups, or any time you bind to 0.0.0.0 instead of 127.0.0.1.
OpenClaw’s gateway protects the Control UI with origin checks to prevent cross-site request forgery (CSRF). When bound to loopback (127.0.0.1), it knows only local connections are possible. When bound to a network interface, it needs you to explicitly declare which origins (browser URLs) are allowed to connect.
Edit your openclaw.json configuration:
{
"gateway": {
"bind": "0.0.0.0:18789",
"controlui": {
"allowedorigins": [
"http://192.168.1.100:18789",
"https://openclaw.yourdomain.com"
]
}
}
}Or via the CLI:
openclaw configure --set gateway.controlui.allowedorigins='["http://192.168.1.100:18789"]'Replace 192.168.1.100 with your actual server IP or domain name. The origin must match exactly what appears in your browser’s address bar — including protocol, hostname, and port.
If you’re behind a reverse proxy that sets the Host header correctly, or you’re on a trusted network:
{
"gateway": {
"controlui": {
"dangerouslyallowhostheaderoriginfallback": true
}
}
}openclaw configure --set gateway.controlui.dangerouslyallowhostheaderoriginfallback=trueWarning: The setting name includes “dangerously” for a reason. Only use this on trusted networks or behind a properly configured reverse proxy. On a public-facing server without a reverse proxy, this weakens CSRF protection.
If you don’t need the UI accessible from the network, keep the gateway bound to loopback and use an SSH tunnel:
# From your local machine:
ssh -L 18789:localhost:18789 user@your-server
# Then open http://localhost:18789 in your browserThis is the most secure option — no origin configuration needed, and the Control UI never touches the network.
{
"gateway": {
"bind": "0.0.0.0:18789",
"controlui": {
"allowedorigins": [
"https://openclaw.yourdomain.com"
]
}
}
}Pair this with a reverse proxy (nginx, Caddy) that terminates TLS:
server {
listen 443 ssl;
server_name openclaw.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/openclaw.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/openclaw.yourdomain.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:18789;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}{
"gateway": {
"bind": "0.0.0.0:18789",
"controlui": {
"allowedorigins": [
"http://192.168.1.50:18789",
"http://homelab.local:18789"
]
}
}
}# docker-compose.yml
services:
openclaw:
image: openclaw/openclaw:latest
ports:
- "18789:18789"
volumes:
- ./openclaw.json:/home/node/.openclaw/openclaw.json
environment:
- OPENCLAW_GATEWAY_BIND=0.0.0.0:18789Make sure your openclaw.json inside the container has the correct allowedorigins set to the URL you’ll access from your browser.
Restart the gateway:
openclaw gateway restartVerify it’s running:
openclaw gateway statusThen open the Control UI in your browser at the origin you configured. If you still see issues, check:
allowedorigins entries (protocol + host + port)Host, Upgrade, and Connection headers are forwardedAI & Cloud Advisor with 18+ years experience. Author of 8 technical books, creator of Ansible Pilot, and instructor at CopyPasteLearn Academy. Speaker at KubeCon EU & Red Hat Summit 2026.
Running OpenClaw in Docker and getting connection refused? Common issues with port mapping, bind addresses, DNS resolution, and WebSocket upgrades explained with fixes.
Troubleshoot OpenClaw API key issues across OpenAI, Anthropic, and GitHub Copilot. Covers 401 errors, invalid key formats, rate limits, and model fallback configuration.
The OpenClaw origin not allowed error means your browser URL does not match the gateway's allowed origins list. Here is how to diagnose and fix it in 60 seconds.