Skip to content

Commit d1837e1

Browse files
JohanYPclaude
andcommitted
chore(docker): ship extra_hosts so vector memory works zero-config
Adding `host.docker.internal:host-gateway` to the bot service in docker-compose.yml means an Ollama (or any other host-side embedding provider) just works after the user fills EMBEDDING_BASE_URL — no docker-compose edit + recreate dance. The mapping is harmless when not in use (just a /etc/hosts entry inside the container). docs/VECTOR_MEMORY.md drops the manual compose tweak step and gains a clearer Ollama systemd override snippet (OLLAMA_HOST=0.0.0.0:11434), plus a security callout to firewall the port from the public internet. README's "no host.docker.internal" line is now wrong and is replaced with the actual behaviour. Requires Docker 20.10+ (released Dec 2020) for host-gateway. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3c36b1b commit d1837e1

3 files changed

Lines changed: 53 additions & 13 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Beyond the basic scheduled tasks, three cron types are supported via `memory/cro
111111
An interactive `setup.sh` script guides you through the full configuration in 10 steps — no manual `.env` editing needed.
112112

113113
### Single Install Path: Docker
114-
Everything runs in Docker — bot and OpenCode together. Updates are a one-liner: `git pull && docker compose up -d --build`. No systemd, no launchd, no `host.docker.internal`.
114+
Everything runs in Docker — bot and OpenCode together. Updates are a one-liner: `git pull && docker compose up -d --build`. No systemd, no launchd, no manual networking. The bot can also reach optional services on the host (e.g. Ollama for vector memory) via `host.docker.internal` out of the box.
115115

116116
---
117117

docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ services:
2323
- ./memory:/app/memory
2424
- bot-data:/app/data
2525
env_file: .env
26+
# Lets the bot reach services running on the VPS host (e.g. an
27+
# Ollama install for the optional vector memory). Harmless when
28+
# unused — it only adds a /etc/hosts alias inside the container.
29+
# Requires Docker 20.10+ (released 2020-12).
30+
extra_hosts:
31+
- "host.docker.internal:host-gateway"
2632
# MCP HTTP server is exposed only on the compose network (no host port
2733
# mapping). OpenCode reaches it at http://bot:4097/mcp.
2834
expose:

docs/VECTOR_MEMORY.md

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,73 @@ substring matching. Everything else works the same.
2424
(fire-and-forget). If the provider is down, the fact is still saved;
2525
re-embed it later with `/memory_reembed`.
2626

27-
## Setup A — Ollama (local, no API key)
27+
## Setup A — Ollama on the host (recommended, no API key)
2828

2929
Best for self-hosted setups. Embeddings never leave your machine.
30+
The `docker-compose.yml` already maps `host.docker.internal` to your
31+
host, so the bot inside Docker can reach Ollama out of the box —
32+
**you don't need to edit the compose file**.
33+
34+
### 1. Install Ollama on the host (VPS / your machine)
3035

3136
```bash
32-
# 1. Install Ollama (https://ollama.com)
3337
curl -fsSL https://ollama.com/install.sh | sh
38+
```
3439

35-
# 2. Pull a small embedding model (~270 MB, runs on CPU)
36-
ollama pull nomic-embed-text
40+
Linux distributions register it as a systemd service automatically.
41+
42+
### 2. Make Ollama listen on all interfaces (so Docker can reach it)
43+
44+
By default Ollama binds to `127.0.0.1`, which is unreachable from
45+
inside containers. Bind it to `0.0.0.0`:
46+
47+
```bash
48+
sudo systemctl edit ollama
49+
```
50+
51+
In the editor that opens, paste:
52+
53+
```ini
54+
[Service]
55+
Environment="OLLAMA_HOST=0.0.0.0:11434"
56+
```
57+
58+
Then reload and restart:
59+
60+
```bash
61+
sudo systemctl daemon-reload
62+
sudo systemctl restart ollama
63+
```
3764

38-
# 3. Make sure Ollama is reachable from inside the bot container.
39-
# On Linux Docker hosts, `host.docker.internal` works since Docker 20.10
40-
# when the compose file has `extra_hosts: ["host.docker.internal:host-gateway"]`
41-
# (already configured in our docker-compose.yml).
42-
ollama serve # listens on :11434 by default
65+
> **Security note:** `0.0.0.0` opens the port on every interface. If
66+
> your VPS is exposed to the internet, block public access:
67+
> `sudo ufw deny 11434/tcp` (or the firewalld equivalent). Docker
68+
> still reaches it locally because containers share the host kernel.
69+
70+
### 3. Pull the embedding model (~270 MB, runs on CPU)
71+
72+
```bash
73+
ollama pull nomic-embed-text
4374
```
4475

45-
Then in `.env`:
76+
### 4. Tell the bot about it
77+
78+
In `.env`:
4679

4780
```env
4881
EMBEDDING_BASE_URL=http://host.docker.internal:11434/v1
4982
EMBEDDING_MODEL=nomic-embed-text
5083
EMBEDDING_API_KEY=
5184
```
5285

53-
Restart the bot:
86+
### 5. Restart and validate
5487

5588
```bash
5689
docker compose restart bot
90+
docker compose logs bot 2>&1 | grep -i embedding
5791
```
5892

59-
In the bot logs you should see:
93+
You should see:
6094

6195
```
6296
[Memory/Embedding] Driver enabled (model=nomic-embed-text, base=http://host.docker.internal:11434/v1, dims≈768)

0 commit comments

Comments
 (0)