|
| 1 | +# Docker Setup for unreal-index |
| 2 | + |
| 3 | +## Prerequisites |
| 4 | + |
| 5 | +- **Docker Desktop for Windows** with WSL 2 backend enabled |
| 6 | +- At least **4 GB RAM** allocated to Docker (Settings > Resources > Memory) |
| 7 | +- The Windows watcher (`node src\watcher\watcher-client.js`) runs outside the container |
| 8 | + |
| 9 | +## Quick Start |
| 10 | + |
| 11 | +```bash |
| 12 | +# Build and start the service |
| 13 | +docker compose up -d |
| 14 | + |
| 15 | +# Verify it's running |
| 16 | +curl http://localhost:3847/health |
| 17 | + |
| 18 | +# Start the watcher on Windows (separate terminal) |
| 19 | +node src\watcher\watcher-client.js |
| 20 | +``` |
| 21 | + |
| 22 | +Or use the convenience script: |
| 23 | + |
| 24 | +```bash |
| 25 | +./start-service.sh --docker |
| 26 | +``` |
| 27 | + |
| 28 | +## Architecture |
| 29 | + |
| 30 | +``` |
| 31 | + Windows Host |
| 32 | + ┌─────────────────────────────────────┐ |
| 33 | + │ Watcher (node watcher-client.js) │ |
| 34 | + │ reads P4 workspace files │ |
| 35 | + │ parses AS/C++/assets │ |
| 36 | + │ │ │ |
| 37 | + │ │ POST /internal/ingest │ |
| 38 | + │ ▼ │ |
| 39 | + │ ┌─────────────────────────────┐ │ |
| 40 | + │ │ Docker Container │ │ |
| 41 | + │ │ ┌───────────────────┐ │ │ |
| 42 | + │ │ │ Node.js Service │:3847│◄───┼── Claude Code / MCP |
| 43 | + │ │ │ (Express API) │ │ │ |
| 44 | + │ │ │ SQLite + Memory │ │ │ |
| 45 | + │ │ └───────┬───────────┘ │ │ |
| 46 | + │ │ │ │ │ |
| 47 | + │ │ ┌───────▼───────────┐ │ │ |
| 48 | + │ │ │ Zoekt │ │ │ |
| 49 | + │ │ │ (index + web) │ │ │ |
| 50 | + │ │ └───────────────────┘ │ │ |
| 51 | + │ │ │ │ |
| 52 | + │ │ Volumes: │ │ |
| 53 | + │ │ /data/db (SQLite) │ │ |
| 54 | + │ │ /data/mirror (Zoekt src) │ │ |
| 55 | + │ │ /data/zoekt-index (shards)│ │ |
| 56 | + │ └─────────────────────────────┘ │ |
| 57 | + └─────────────────────────────────────┘ |
| 58 | +``` |
| 59 | + |
| 60 | +## Configuration |
| 61 | + |
| 62 | +The container uses `config.docker.json` as the default config. Key settings: |
| 63 | + |
| 64 | +| Setting | Default | Description | |
| 65 | +|---------|---------|-------------| |
| 66 | +| `service.host` | `0.0.0.0` | Required for Docker port mapping | |
| 67 | +| `service.port` | `3847` | API port | |
| 68 | +| `data.dbPath` | `/data/db/index.db` | SQLite database path | |
| 69 | +| `data.mirrorDir` | `/data/mirror` | Zoekt mirror directory | |
| 70 | +| `data.indexDir` | `/data/zoekt-index` | Zoekt index shards | |
| 71 | +| `zoekt.parallelism` | `4` | Zoekt indexing threads | |
| 72 | +| `projects` | `[]` | Empty — data arrives via `/internal/ingest` | |
| 73 | + |
| 74 | +### Custom config |
| 75 | + |
| 76 | +Mount a custom config file: |
| 77 | + |
| 78 | +```yaml |
| 79 | +# docker-compose.override.yml |
| 80 | +services: |
| 81 | + unreal-index: |
| 82 | + volumes: |
| 83 | + - ./my-config.json:/app/config.json:ro |
| 84 | +``` |
| 85 | +
|
| 86 | +### Environment variables |
| 87 | +
|
| 88 | +- `UNREAL_INDEX_CONFIG` — path to config file (overrides default) |
| 89 | +- `NODE_OPTIONS` — Node.js options (default: `--max-old-space-size=3072`) |
| 90 | + |
| 91 | +## Data Persistence |
| 92 | + |
| 93 | +Data is stored in three Docker named volumes: |
| 94 | + |
| 95 | +| Volume | Contents | Purpose | |
| 96 | +|--------|----------|---------| |
| 97 | +| `unreal-index-db` | `index.db` | SQLite database | |
| 98 | +| `unreal-index-mirror` | Source files | Zoekt mirror for grep | |
| 99 | +| `unreal-index-zoekt` | Index shards | Zoekt search index | |
| 100 | + |
| 101 | +### Lifecycle |
| 102 | + |
| 103 | +```bash |
| 104 | +# Stop container (data preserved) |
| 105 | +docker compose down |
| 106 | +
|
| 107 | +# Start again (data still there) |
| 108 | +docker compose up -d |
| 109 | +
|
| 110 | +# DANGER: Remove data volumes |
| 111 | +docker compose down -v |
| 112 | +``` |
| 113 | + |
| 114 | +### Backup |
| 115 | + |
| 116 | +```bash |
| 117 | +# Backup database |
| 118 | +docker compose exec unreal-index cp /data/db/index.db /data/db/index.db.bak |
| 119 | +
|
| 120 | +# Copy database to host |
| 121 | +docker compose cp unreal-index:/data/db/index.db ./backup-index.db |
| 122 | +``` |
| 123 | + |
| 124 | +### Restore |
| 125 | + |
| 126 | +```bash |
| 127 | +# Copy database into container |
| 128 | +docker compose cp ./backup-index.db unreal-index:/data/db/index.db |
| 129 | +
|
| 130 | +# Restart to load |
| 131 | +docker compose restart |
| 132 | +``` |
| 133 | + |
| 134 | +## Memory Configuration |
| 135 | + |
| 136 | +The container is limited to 4 GB RAM: |
| 137 | +- **3 GB** — Node.js heap (`--max-old-space-size=3072`) |
| 138 | +- **~1 GB** — Zoekt processes, OS overhead, SQLite mmap |
| 139 | + |
| 140 | +For larger codebases, increase both limits in `docker-compose.yml`: |
| 141 | + |
| 142 | +```yaml |
| 143 | +services: |
| 144 | + unreal-index: |
| 145 | + mem_limit: 6g |
| 146 | + memswap_limit: 6g |
| 147 | + environment: |
| 148 | + - NODE_OPTIONS=--max-old-space-size=4096 |
| 149 | +``` |
| 150 | + |
| 151 | +Also ensure Docker Desktop has sufficient RAM allocated (Settings > Resources). |
| 152 | + |
| 153 | +## Troubleshooting |
| 154 | + |
| 155 | +### Port conflict |
| 156 | + |
| 157 | +``` |
| 158 | +Error: listen EADDRINUSE: address already in use :::3847 |
| 159 | +``` |
| 160 | +
|
| 161 | +Another process is using port 3847. Stop it or change the port mapping: |
| 162 | +
|
| 163 | +```yaml |
| 164 | +ports: |
| 165 | + - "3848:3847" # Use 3848 on host |
| 166 | +``` |
| 167 | + |
| 168 | +### Container OOM killed |
| 169 | + |
| 170 | +```bash |
| 171 | +# Check if container was OOM killed |
| 172 | +docker inspect unreal-index | grep -A 5 OOMKilled |
| 173 | +``` |
| 174 | + |
| 175 | +Increase `mem_limit` in `docker-compose.yml` and Docker Desktop RAM allocation. |
| 176 | + |
| 177 | +### Slow queries after restart |
| 178 | + |
| 179 | +The in-memory index needs to reload from SQLite on startup (~10s for large indexes). Queries during this window may be slow or return empty results. The health check accounts for this with a 30s start period. |
| 180 | + |
| 181 | +### SQLite errors |
| 182 | + |
| 183 | +SQLite runs on a Docker named volume (ext4 filesystem). This avoids the performance issues of bind-mounting from Windows NTFS. If you see locking errors, ensure only one container is running: |
| 184 | + |
| 185 | +```bash |
| 186 | +docker compose ps |
| 187 | +``` |
| 188 | + |
| 189 | +### Viewing logs |
| 190 | + |
| 191 | +```bash |
| 192 | +# Follow logs |
| 193 | +docker compose logs -f |
| 194 | + |
| 195 | +# Last 100 lines |
| 196 | +docker compose logs --tail=100 |
| 197 | +``` |
| 198 | + |
| 199 | +## Development |
| 200 | + |
| 201 | +Use the dev compose override for source mounting with auto-reload: |
| 202 | + |
| 203 | +```bash |
| 204 | +docker compose -f docker-compose.yml -f docker-compose.dev.yml up |
| 205 | +``` |
| 206 | + |
| 207 | +This mounts `src/` and `public/` as read-only volumes and enables Node.js `--watch` mode. The container rebuilds only when dependencies change. |
| 208 | + |
| 209 | +To rebuild after dependency changes: |
| 210 | + |
| 211 | +```bash |
| 212 | +docker compose build |
| 213 | +``` |
| 214 | + |
| 215 | +## Performance Testing |
| 216 | + |
| 217 | +Run the Docker performance test from the host: |
| 218 | + |
| 219 | +```bash |
| 220 | +node test-docker-perf.mjs |
| 221 | +``` |
| 222 | + |
| 223 | +With a baseline comparison: |
| 224 | + |
| 225 | +```bash |
| 226 | +node test-docker-perf.mjs --baseline perf-baseline-wsl.json |
| 227 | +``` |
| 228 | + |
| 229 | +Long-running stability test (30 minutes): |
| 230 | + |
| 231 | +```bash |
| 232 | +node test-docker-perf.mjs --long-run |
| 233 | +``` |
| 234 | + |
| 235 | +## Docker vs WSL Comparison |
| 236 | + |
| 237 | +| Aspect | WSL (current) | Docker | |
| 238 | +|--------|---------------|--------| |
| 239 | +| **Setup** | Manual: Node 22, Go, Zoekt build, screen | `docker compose up -d` | |
| 240 | +| **Networking** | WSL mirrored mode, screen hacks | Standard port mapping | |
| 241 | +| **Persistence** | `~/.unreal-index/` on ext4 | Named volumes (ext4) | |
| 242 | +| **Updates** | `git pull && npm install` | `docker compose build && up -d` | |
| 243 | +| **Memory** | Shared with WSL | Isolated, configurable limit | |
| 244 | +| **Startup** | ~10s (warm) | ~15s (warm, includes container overhead) | |
| 245 | +| **SQLite perf** | Native ext4 | Named volume ext4 (equivalent) | |
| 246 | +| **Background** | Requires `screen` | Built-in container lifecycle | |
| 247 | +| **Portability** | Tied to this machine's WSL setup | Any Docker host | |
0 commit comments