Fix Ollama 'Error: connect ECONNREFUSED 127.0.0.1:11434' from Docker or Local AI Apps
Diagnose port 11434 listeners with `npx castov port 11434` and configure `OLLAMA_HOST=0.0.0.0:11434` for Docker container access.
Error: fetch failed — connect ECONNREFUSED 127.0.0.1:11434
# 1. Check if Ollama is actively listening on port 11434: npx castov port 11434 # 2. Allow Docker containers to connect to host Ollama: OLLAMA_HOST=0.0.0.0:11434 ollama serve
Root Cause & Mechanism Analysis
Why does this error occur?
Either the `ollama serve` daemon is not running on port `11434`, or a Docker container is trying to reach Ollama on `127.0.0.1:11434` while Ollama is bound only to the host loopback interface (`127.0.0.1`) instead of `0.0.0.0`.
Frequently Asked Questions
Is it safe to set `OLLAMA_HOST=0.0.0.0:11434` on a public cloud VM?
Need Zero-Knowledge .env Secret Sync Across Your Engineering Team?
Explore Castov Env Vault for client-side AES-256-GCM encrypted environment sharing, or sponsor this engineering hub.
Related Developer Error Solutions
Browse All 54 GuidesDocker Compose: the attribute `version` is obsolete
Modernize `compose.yaml` to the Compose Specification and fix `localhost` vs service-name networking between containers.
Docker: Bind for 0.0.0.0:Port Failed
Identify and terminate conflicting host processes or adjust Docker port mapping to resolve port bind collisions.
Next.js Hydration Failed
Resolve Next.js React hydration mismatch errors caused by browser-only APIs (window, localStorage), timestamps, or invalid HTML nesting.
CORS 'Access-Control-Allow-Origin' Missing
Resolve browser cross-origin resource sharing errors by configuring backend HTTP headers and handling preflight OPTIONS requests.