sourced
Sourced guidance · Ollama + Docker Compose · Ollama local API and Docker Compose networking; source review 2026-11-05
Check this fix
- Applies when
- The app container reports connection refused for http://localhost:11434/api/generate or /api/chat, while Ollama responds elsewhere.
- Change to inspect
- If both containers share a Compose network and the Ollama service is named ollama, set the app client base URL to http://ollama:11434 (or http://ollama:11434/api if that client expects the /api prefix).
- Expected result
- Upstream users reported a working host/service address; no Kingy reproduction or reader completion has been observed. The verification steps are proposed checks, not a measured success rate.
- If it still fails
- Keep the original failed output and check the conditions and verification steps below. Retained failed attempt: The upstream issue reports this symptom and an Ollama contributor identifies container-local localhost as the cause in the described deployment. Kingy has no retained local failed/corrected attempt.
Tested or reviewed 2026-11-05. Verify the original task on your own version and settings; this case does not prove a universal fix.
Read the verification steps ↓ · Report your outcome ↓What happened
Symptom
The app container reports connection refused for http://localhost:11434/api/generate or /api/chat, while Ollama responds elsewhere.
Exact environment and tested conditions
The failing client runs inside a Docker Compose container; the Ollama server runs as a separate service named ollama on the same Compose network.
Check the client library base-URL convention before adding /api; do not add it twice. This page does not apply to a host-only client or to a server that is stopped.
Correction
If both containers share a Compose network and the Ollama service is named ollama, set the app client base URL to http://ollama:11434 (or http://ollama:11434/api if that client expects the /api prefix).
Result
Upstream users reported a working host/service address; no Kingy reproduction or reader completion has been observed. The verification steps are proposed checks, not a measured success rate.
What did not work
The upstream issue reports this symptom and an Ollama contributor identifies container-local localhost as the cause in the described deployment. Kingy has no retained local failed/corrected attempt.
- From the app container, inspect the configured endpoint. A localhost address resolves within that app container, not the Ollama service.
- Confirm the Ollama service is running and that both services share a Compose network. From the app container, request http://ollama:11434/api/tags; expect an HTTP response containing the available model list.
- Change only the client base URL to the same-network service address. Keep the original model and task unchanged.
- Retry the original request. Success means the connection error disappears and the original application response/check completes; an HTTP error or empty model list requires separate diagnosis.
Sources & limits
Ollama issue 3200: container localhost connection refused and maintainer explanation
Docker Compose service discovery and container networking
Ollama local API base URL and endpoint reference
Record checked 2026-11-05.
Source-backed guidance reviewed 2026-11-05. Not tested by Kingy on a container pair or a user application.
Service-name resolution requires a shared Compose network and the actual service name. A refusal after the change may mean Ollama is not running, is listening on another interface, or the containers lack a shared network.
Do not make Ollama publicly reachable just to fix an internal service URL.