Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(docker): reach host Ollama via host.docker.internal (#196)

Shah Newaz Khanb6fd9b1fd4e2
diff --git a/README.md b/README.md
index c2459ffff..d3a34857d 100644
--- a/README.md
+++ b/README.md
@@ -443,6 +443,9 @@ Open `http://localhost:8899`. Backend + frontend in one container.
Docker publishes the backend on `127.0.0.1:8899` by default and runs the app as a non-root container user. If you intentionally expose the API beyond your own machine, set a strong `API_AUTH_KEY` and send `Authorization: Bearer <key>` from clients.
+> [!NOTE]
+> **Using Ollama with Docker:** the container reaches a host-side Ollama via `host.docker.internal`, not `localhost` (inside the container `localhost` is the container itself). `docker-compose.yml` defaults `OLLAMA_BASE_URL` to `http://host.docker.internal:11434`; export `OLLAMA_BASE_URL` (or set it in a top-level `.env`) to point elsewhere. This relies on the `host-gateway` mapping in `extra_hosts`, which requires **Docker Engine ≥ 20.10 / Compose v2** (provided automatically on Docker Desktop).
+
### Path B: Local install
```bash
diff --git a/docker-compose.yml b/docker-compose.yml
index 1fa28b3f7..4d02e4217 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -7,6 +7,15 @@ services:
- agent/.env
environment:
- VIBE_TRADING_TRUST_DOCKER_LOOPBACK=1
+ # Ollama runs on the host; from inside the container "localhost" is the
+ # container itself, so default to reaching the host via host.docker.internal.
+ # Override by exporting OLLAMA_BASE_URL (or setting it in a top-level .env)
+ # when Ollama runs elsewhere or on a different port.
+ - OLLAMA_BASE_URL=${OLLAMA_BASE_URL:-http://host.docker.internal:11434}
+ extra_hosts:
+ # Maps host.docker.internal -> host gateway (needed on Linux; harmless on Docker Desktop).
+ # Requires Docker Engine >= 20.10 / Compose v2 (host-gateway support).
+ - "host.docker.internal:host-gateway"
volumes:
- vibe-runs:/app/agent/runs
- vibe-sessions:/app/agent/sessions