Khoj with Docker Compose
Your AI second brain. Self-hostable. Get answers from the web or your docs. Build custom agents, schedule automations, do deep research. In the project's words: Khoj on GitHub (repository description) checked 2026-10-01
Runs on: amd64, arm64 from each image's registry manifest, checked 2026-10-01; a CPU counts only if every image has a build for it. Image by image
Add Khoj to the builder to use your own domain, get its passwords generated in your browser, and combine it with other apps in one file.
What Khoj needs
Only figures Khoj's own documentation publishes, each linked to the page it is on. Where the project gives no number, this page does not invent one.
| Resource | Minimum | Recommended |
|---|---|---|
| RAM | The project publishes no figure | |
| The setup page's "Minimum 8 GB RAM" and "Minimum 5 GB of Disk" are for running an offline chat model, which this file does not include: it talks to the model provider you add. Source: Khoj docs: Setup (Docker, admin credentials, anonymous mode, admin panel, offline chat requirements) checked 2026-10-01 | ||
| CPU | The project publishes no figure | |
| Disk | The project publishes no figure | |
Which hardware Khoj has images for
Read from each image's manifest list in its registry (anonymous, read-only) when this page was built. An app counts for a CPU only if every one of its images lists it.
- x86-64 PC or NAS (
linux/amd64): every image has a build. - Raspberry Pi 4/5, 64-bit OS (
linux/arm64): every image has a build. - Raspberry Pi 3 or Zero 2 W, 32-bit OS (
linux/arm/v7): no image fordatabase,sandbox,server. No image for this hardware; the builder leaves the app out.
| Service | Image | Platforms in the manifest | Digest | Registry | Checked |
|---|---|---|---|---|---|
database | docker.io/pgvector/pgvector:pg15 | amd64, arm64 | sha256:a947c45cdc5906a1bc951f20a8709e321256343ee0f251e4ae00b5e7def4e6da | registry-1.docker.io | 2026-10-01 |
sandbox | ghcr.io/khoj-ai/terrarium:latest | amd64, arm64 | sha256:caf9356305daf9f7f4e4a63ef1ce3a72dc2c0190cb8fdfa4e0e837d2298f19ce | ghcr.io | 2026-10-01 |
search | docker.io/searxng/searxng:latest | amd64, arm64, arm/v7 | sha256:a07a5cd2da2c63d66e559f9e4d3a3db106cfc6c32fb0ac70abe91cc28bcd7350 | registry-1.docker.io | 2026-09-30 |
server | ghcr.io/khoj-ai/khoj:latest | amd64, arm64 | sha256:41aa881c957a035207c11da239dc436d0f8a0c6a72b372651c5a48e08127043a | ghcr.io | 2026-10-01 |
docker-compose.yml
This is exactly what the builder writes for Khoj alone on example.org: the official definition with its published ports removed and Caddy added in front. Every ${VARIABLE} is defined in the .env below.
# docker-compose.yml built at dankhost.com for: Khoj # Each app block is its official compose definition. Only the names were prefixed with # the app slug (services, containers, volumes, bind folders, .env variables) so any set of # apps can share one file; other differences are listed under "Changed:" in each block. # Only Caddy publishes ports. Secrets live in .env next to this file. services: # ---- Caddy: the one reverse proxy, HTTPS certificates from Let's Encrypt ---- # Source: https://caddyserver.com/docs/running (checked 2026-09-23) # Source: https://github.com/dani-garcia/vaultwarden/wiki/Using-Docker-Compose (checked 2026-09-23) # Caddyfile goes in ./caddy/Caddyfile. Fixed address 172.30.0.2 so apps can trust it exactly. caddy: image: "caddy:2" container_name: "caddy" restart: "unless-stopped" ports: - "80:80" - "443:443" - "443:443/udp" volumes: - "./caddy:/etc/caddy" - "caddy-data:/data" - "caddy-config:/config" networks: proxy: ipv4_address: "172.30.0.2" # ---- Khoj (khoj.example.org) ---- # Source: https://github.com/khoj-ai/khoj/blob/master/docker-compose.yml (checked 2026-10-01) # Source: https://github.com/khoj-ai/khoj/blob/master/documentation/docs/get-started/setup.mdx (checked 2026-10-01) # Source: https://github.com/khoj-ai/khoj/blob/master/documentation/docs/advanced/remote.md (checked 2026-10-01) # Changed: Removed the documented '42110:42110' port; Caddy reaches khoj-server:42110 on the proxy network. # Left out the computer service (ghcr.io/khoj-ai/khoj-computer:latest). The file says it is used only with KHOJ_OPERATOR_ENABLED=True, which it leaves commented out, and it publishes a VNC port, 5900, on the host. # The file's example values postgres, secret and password are generated in .env: POSTGRES_PASSWORD for both database and server, KHOJ_DJANGO_SECRET_KEY and KHOJ_ADMIN_PASSWORD, which the setup page says to set "to something secure". KHOJ_ADMIN_EMAIL is in .env for you to change. # Added KHOJ_DOMAIN, set to this app's address (khoj.example.org). The file's comment and the Remote Access page say to set it to the domain Khoj is reached on; without it Django answers "DISALLOWED HOST". khoj-database: image: "docker.io/pgvector/pgvector:pg15" container_name: "khoj-database" environment: POSTGRES_USER: "postgres" POSTGRES_PASSWORD: "${KHOJ_POSTGRES_PASSWORD}" POSTGRES_DB: "postgres" volumes: - "khoj-khoj_db:/var/lib/postgresql/data/" healthcheck: test: - "CMD-SHELL" - "pg_isready -U postgres" interval: "30s" timeout: "10s" retries: 5 networks: khoj-backend: aliases: - "database" khoj-sandbox: image: "ghcr.io/khoj-ai/terrarium:latest" container_name: "khoj-sandbox" healthcheck: test: - "CMD-SHELL" - "curl -f http://localhost:8080/health" interval: "30s" timeout: "10s" retries: 2 networks: khoj-backend: aliases: - "sandbox" khoj-search: image: "docker.io/searxng/searxng:latest" container_name: "khoj-search" volumes: - "khoj-khoj_search:/etc/searxng" environment: SEARXNG_BASE_URL: "http://localhost:8080/" networks: khoj-backend: aliases: - "search" khoj-server: depends_on: khoj-database: condition: "service_healthy" image: "ghcr.io/khoj-ai/khoj:latest" container_name: "khoj-server" extra_hosts: - "host.docker.internal:host-gateway" working_dir: "/app" volumes: - "khoj-khoj_config:/root/.khoj/" - "khoj-khoj_models:/root/.cache/torch/sentence_transformers" - "khoj-khoj_models:/root/.cache/huggingface" environment: POSTGRES_DB: "postgres" POSTGRES_USER: "postgres" POSTGRES_PASSWORD: "${KHOJ_POSTGRES_PASSWORD}" POSTGRES_HOST: "database" POSTGRES_PORT: "5432" KHOJ_DJANGO_SECRET_KEY: "${KHOJ_DJANGO_SECRET_KEY}" KHOJ_DEBUG: "False" KHOJ_ADMIN_EMAIL: "${KHOJ_ADMIN_EMAIL}" KHOJ_ADMIN_PASSWORD: "${KHOJ_ADMIN_PASSWORD}" KHOJ_TERRARIUM_URL: "http://sandbox:8080" KHOJ_SEARXNG_URL: "http://search:8080" KHOJ_DOMAIN: "khoj.example.org" command: "--host=\"0.0.0.0\" --port=42110 -vv --anonymous-mode --non-interactive" networks: proxy: {} khoj-backend: aliases: - "server" networks: # Pinned so the trusted-proxy address given to each app (172.30.0.2) is exact. # If "docker compose up" reports "Pool overlaps", change 172.30.0 here, in Caddy's # ipv4_address and in every trusted-proxy value to a free 172.x.0 range. proxy: ipam: config: - subnet: "172.30.0.0/24" ip_range: "172.30.0.128/25" gateway: "172.30.0.1" khoj-backend: internal: true volumes: caddy-data: caddy-config: khoj-khoj_config: khoj-khoj_db: khoj-khoj_models: khoj-khoj_search:
Caddyfile save as caddy/Caddyfile
Caddy gets and renews the HTTPS certificate for khoj.example.org by itself once the DNS record points at your server and ports 80 and 443 reach it.
# Caddyfile built at dankhost.com. Save it as ./caddy/Caddyfile next to docker-compose.yml.
# Caddy gets and renews a Let's Encrypt certificate for each name below by itself,
# once the DNS records point at this server and ports 80 and 443 reach it.
# Khoj
khoj.example.org {
reverse_proxy khoj-server:42110
}
.env
The secrets are left blank here on purpose: a password printed on a public page is the same for everyone who copies it. The builder fills them with random letters and digits made in your browser.
# .env for Khoj, from dankhost.com/app/khoj/. Fill the blank secrets before starting. # Keep this file private (chmod 600). # Khoj # 32 random letters and digits: the builder fills this in your browser KHOJ_POSTGRES_PASSWORD= # 50 random letters and digits: the builder fills this in your browser KHOJ_DJANGO_SECRET_KEY= # Khoj's admin login: put your own address here before the first start. KHOJ_ADMIN_EMAIL=username@example.com # 24 random letters and digits: the builder fills this in your browser KHOJ_ADMIN_PASSWORD=
Changes from the official file
Besides prefixing every service, container, volume, folder and variable with khoj (so any set of apps can share one file), these are all the differences from what the project documents:
- Removed the documented '42110:42110' port; Caddy reaches khoj-server:42110 on the proxy network.
- Left out the computer service (ghcr.io/khoj-ai/khoj-computer:latest). The file says it is used only with KHOJ_OPERATOR_ENABLED=True, which it leaves commented out, and it publishes a VNC port, 5900, on the host.
- The file's example values postgres, secret and password are generated in .env: POSTGRES_PASSWORD for both database and server, KHOJ_DJANGO_SECRET_KEY and KHOJ_ADMIN_PASSWORD, which the setup page says to set "to something secure". KHOJ_ADMIN_EMAIL is in .env for you to change.
- Added KHOJ_DOMAIN, set to this app's address (khoj.example.org). The file's comment and the Remote Access page say to set it to the domain Khoj is reached on; without it Django answers "DISALLOWED HOST".
Notes for Khoj behind the proxy
- The file starts Khoj with --anonymous-mode, kept here: anyone who reaches https://khoj.example.org can chat, with no login, on your model provider's account. The setup page calls that "usually fine for local only, single user setups". If the address is reachable from the internet, choose the builder's home-network or VPN access, or tick Authelia to put a login in front.
- Then open https://khoj.example.org/server/admin, log in with KHOJ_ADMIN_EMAIL and KHOJ_ADMIN_PASSWORD from .env, and add an AI model API and a chat model there, as the setup page describes.
- To use Ollama on this machine, uncomment OPENAI_BASE_URL under khoj-server as the file shows: extra_hosts makes host.docker.internal reach the host.
- Every image is on 'latest' (pgvector on its pg15 tag), as in the file.
How to run it
- At your DNS provider, add an A record named
khojon your domain pointing at the server's public IP address, and forward TCP 80, TCP 443 and UDP 443 to it. - Save the three files in one folder:
docker-compose.ymland.envside by side, the Caddyfile at./caddy/Caddyfile. Replaceexample.orgwith your domain in the Caddyfile, the compose file and the .env, or let the builder do it. - Fill the blank
KHOJ_POSTGRES_PASSWORD,KHOJ_DJANGO_SECRET_KEY,KHOJ_ADMIN_PASSWORDin.env. The builder generates them; on the server,tr -dc A-Za-z0-9 </dev/urandom | head -c 32prints 32 random letters and digits. Thenchmod 600 .env. - Start it:
docker compose up -d docker compose logs -f caddy # watch the certificate arrive
- Open the new address (
khoj.plus your domain) in a browser and follow the notes above.
Back it up
Khoj publishes no backup procedure for Docker. Users, chats, agents and your indexed documents with their embeddings are in the Postgres database; the config volume holds Khoj's own folder.
Below is the BACKUP.md the builder writes next to the compose file above: which of its folders and volumes hold data, the dump command the project documents, rewritten for this file's service names, what to copy with which container stopped, and a restore check. Pick more apps in the builder and it covers them all in one file.
# BACKUP.md built at dankhost.com for: Khoj
What to copy from the docker-compose.yml built with this file, the database dump each project documents (rewritten for the service names in that file), what to copy with which container stopped, and how to check the result. Run every command in the folder that holds docker-compose.yml.
The folders are owned by the containers' users: put sudo in front of tar if it says "Permission denied". Named volumes live under /var/lib/docker/volumes, not next to the compose file, so they are copied through a throwaway ubuntu container (Docker's documented --volumes-from method). tar makes a full copy each run; for large folders an incremental tool (restic, borg, rsync) saves time and space.
Never run "docker compose down -v" on this file: it deletes the named volumes of every app in it.
## Before you start
BACKUP=/mnt/backup/selfhost # change this: a disk or machine other than this server's system disk
mkdir -p "$BACKUP"
## Every time: the three stack files
tar czf "$BACKUP/stack-files.tar.gz" docker-compose.yml .env caddy
.env holds the database passwords and secret keys the apps were set up with; keep this archive as private as the data.
## Caddy (the reverse proxy)
Caddy's docs: 'The data directory must not be treated as a cache.' It holds the TLS certificates and their private keys; without it Caddy has to ask Let's Encrypt for every certificate again.
- caddy-data (named volume, /data in caddy)
BACK UP: TLS certificates, private keys, OCSP staples.
- caddy-config (named volume, /config in caddy)
SKIP: the last active configuration, kept for 'caddy run --resume', which this setup does not use: it starts from the Caddyfile.
- ./caddy (/etc/caddy in caddy)
IN stack-files.tar.gz: the Caddyfile, copied with the stack files above.
Copy (Caddy keeps serving while you copy):
docker run --rm --volumes-from caddy -v "$BACKUP":/backup ubuntu tar cvf /backup/caddy-data.tar /data
Restore check:
tar tf "$BACKUP/caddy-data.tar" > /dev/null && echo OK
docker run --rm --volumes-from caddy -v "$BACKUP":/backup ubuntu bash -c "cd /data && tar xvf /backup/caddy-data.tar --strip 1"
Sources:
- Caddy docs: Conventions, Data directory: https://caddyserver.com/docs/conventions#data-directory (checked 2026-09-24)
- Docker docs: Volumes, Back up, restore, or migrate data volumes: https://docs.docker.com/engine/storage/volumes/#back-up-restore-or-migrate-data-volumes (checked 2026-09-24)
## Khoj
Khoj publishes no backup procedure for Docker. Users, chats, agents and your indexed documents with their embeddings are in the Postgres database; the config volume holds Khoj's own folder.
What this compose mounts:
- khoj-khoj_db (named volume, /var/lib/postgresql/data in khoj-database)
COVERED BY THE COMMAND BELOW: Postgres (pgvector) data files; copy them only with the database stopped.
- khoj-khoj_search (named volume, /etc/searxng in khoj-search)
OPTIONAL: SearXNG's settings, written on its first start; keep it if you changed them.
- khoj-khoj_config (named volume, /root/.khoj in khoj-server)
BACK UP: Khoj's ~/.khoj folder.
- khoj-khoj_models (named volume, /root/.cache/torch/sentence_transformers in khoj-server)
SKIP: downloaded embedding models; Khoj fetches them again.
- khoj-khoj_models (named volume, /root/.cache/huggingface in khoj-server)
SKIP: downloaded embedding models; Khoj fetches them again.
1. Database dump for khoj-database:
docker compose exec -T khoj-database pg_dump -U postgres postgres > "$BACKUP/khoj.sql"
Plain pg_dump of the database the file names (user and database both postgres), run through docker compose with -T.
2. Copy (Khoj keeps running):
pg_dump is consistent while Khoj runs: the dump is a snapshot of the database at the moment it started (PostgreSQL docs).
docker run --rm --volumes-from khoj-server -v "$BACKUP":/backup ubuntu tar cvf /backup/khoj-khoj_config.tar /root/.khoj
Restore check:
grep -c 'PostgreSQL database dump complete' "$BACKUP/khoj.sql" # 1 means pg_dump finished
tar tf "$BACKUP/khoj-khoj_config.tar" > /dev/null && echo OK
Put a copy back (with Khoj stopped):
docker run --rm --volumes-from khoj-server -v "$BACKUP":/backup ubuntu bash -c "cd /root/.khoj && tar xvf /backup/khoj-khoj_config.tar --strip 2"
docker compose up -d khoj-database
docker compose exec -T khoj-database psql -U postgres postgres < "$BACKUP/khoj.sql"
Put the config volume back, then:
docker compose up -d
Sources:
- Khoj docs: Setup (Docker, admin credentials, anonymous mode, admin panel, offline chat requirements): https://github.com/khoj-ai/khoj/blob/master/documentation/docs/get-started/setup.mdx (checked 2026-10-01)
- Docker docs: Volumes, Back up, restore, or migrate data volumes: https://docs.docker.com/engine/storage/volumes/#back-up-restore-or-migrate-data-volumes (checked 2026-10-01)
Update it
What docker compose pull does depends only on how each image line in the compose file above is tagged. For Khoj as this page writes it:
| Service | Image | How it is pinned | What docker compose pull does |
|---|---|---|---|
caddy | caddy:2 | Major version only (tag 2) | Takes the newest image tagged 2: minor and patch releases of 2, never 3. A new major version needs a tag edit. |
khoj-database | docker.io/pgvector/pgvector:pg15 | Not pinned: moving tag pg15 | Moves to the newest image published as pg15, which can be a new major version. |
khoj-sandbox | ghcr.io/khoj-ai/terrarium:latest | Not pinned: moving tag latest | Moves to the newest image published as latest, which can be a new major version. |
khoj-search | docker.io/searxng/searxng:latest | Not pinned: moving tag latest | Moves to the newest image published as latest, which can be a new major version. |
khoj-server | ghcr.io/khoj-ai/khoj:latest | Not pinned: moving tag latest | Moves to the newest image published as latest, which can be a new major version. |
What Khoj's docs say about updating
Khoj's setup page, "Upgrade Server", Docker tab: "Run the commands below from the same directory where you have your docker-compose.yml file. This will fetch the latest build and upgrade your server."
docker-compose up --build
- docker-compose is the old spelling of docker compose. --build only matters for a service with a build: section, and this file (like the official one, whose build lines are commented out) has none. What fetches the new images is the latest tag: Docker's Compose reference says "The latest tag is always pulled even when the missing pull policy is used". docker compose pull then docker compose up -d, below, does the same in two steps and runs in the background, where Khoj's command stays attached to the terminal.
- A pull moves khoj, terrarium and searxng to their newest latest images and pgvector to the newest build of its pg15 tag. Chats, settings and indexed files are in the volumes khoj-khoj_db, khoj-khoj_config and khoj-khoj_models (the official file's khoj_db, khoj_config and khoj_models, prefixed with the app's name), so they stay.
The steps
- Back up first, as in Back it up above. An update can migrate Khoj's data on its first start; the copy is the way back.
- Download the new images. Running containers are not touched yet:
docker compose pull
- Recreate the containers whose image changed. Volumes and bind-mounted folders stay as they are:
docker compose up -d
- Watch Khoj start (Ctrl+C stops following the log, not the app):
docker compose logs -f khoj-server
- Optional: remove the old images the pull left without a tag. This covers every stack on the machine, not only this one:
docker image prune
Sources
Every page below was fetched on the date shown.
- Khoj on GitHub (repository description) checked 2026-10-01 (what it does)
- Khoj docs: Setup (Docker, admin credentials, anonymous mode, admin panel, offline chat requirements) checked 2026-10-01 (hardware requirements, compose definition and proxy settings, backup plan, update notes)
- Khoj: docker-compose.yml in the repository (the file the setup page downloads) checked 2026-10-01 (compose definition and proxy settings)
- Khoj docs: Remote Access (KHOJ_DOMAIN, authentication) checked 2026-10-01 (compose definition and proxy settings)
- Caddy docs: Keep Caddy running (Docker Compose section) checked 2026-09-23 (Caddy)
- Vaultwarden wiki: Caddy with HTTP challenge (uses the caddy:2 image) checked 2026-09-23 (Caddy)
- Docker docs: Volumes, Back up, restore, or migrate data volumes checked 2026-10-01 (backup plan)
- Caddy docs: Conventions, Data directory checked 2026-09-24 (backup plan)
- Docker docs: Compose file reference, pull_policy checked 2026-10-01 (update notes)
- Docker docs: docker compose pull checked 2026-09-30 (update steps)
- Docker docs: docker compose up (recreates changed containers, keeps volumes) checked 2026-09-30 (update steps)
- Docker docs: docker image prune checked 2026-09-30 (update steps)