Docker
Run Anvio's API, worker, and gateway services with Docker Compose, in production or dev mode.
5 min read
Anvio ships two Compose files under docker/: a production stack (docker-compose.yml) with built application images, and a dev stack (docker-compose.dev.yml) that runs only the infrastructure dependencies (Postgres, Redis, NATS, Qdrant) while you run the Node apps locally with pnpm dev.
Docker is optional at Level 1. A solo developer can run anvio chat with zero containers. Reach for Docker when you need the API + gateway services, a shared Postgres/Redis/NATS backend, or sandboxed code execution. See the deployment levels table in Environment Variables.
Production stack (docker/docker-compose.yml)
docker compose -f docker/docker-compose.yml up -d| Service | Image / build | Purpose | Ports |
|---|---|---|---|
postgres | postgres:16-alpine | Primary relational store (Level 3) | internal only |
redis | redis:7-alpine | Cache / session state | internal only |
nats | nats:2.10-alpine (-js -m 8222) | JetStream event bus | internal only |
api | docker/Dockerfile.api | REST API (@anvio/api) | 3000:3000 |
worker | docker/Dockerfile.worker | Agent runtime, tool execution, background jobs | none published |
gateway | docker/Dockerfile.gateway | Channel/WS gateway (@anvio/gateway) | 3001:3001 |
All three application services build from repo root (context: ..) using their respective Dockerfiles, and share the same Postgres/Redis/NATS backends via internal Docker networking (postgres:5432, redis:6379, nats:4222).
Health checks and startup order
Each infra service has a healthcheck, and api/worker declare depends_on with condition: service_healthy so they wait for Postgres, Redis, and NATS to actually be ready (not just started):
postgres:
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-anvio}"]
interval: 10s
timeout: 5s
retries: 5
nats:
command: ["-js", "-m", "8222"]
healthcheck:
test: ["CMD", "wget", "-q", "--spider", "http://localhost:8222/healthz"]gateway depends on api, nats, and redis but without a health-gated condition — it retries its own connections on boot.
All application services set restart: unless-stopped.
Required environment
The production compose file interpolates these from your shell or an .env file next to the compose file:
POSTGRES_USER,POSTGRES_PASSWORD,POSTGRES_DB(default toanvio/anvio/anvio— change in production)ANTHROPIC_API_KEY— passed into bothapiandworkerJWT_SECRET— passed intoapiandgateway, only meaningful whenauth.enabled: true
See Environment Variables for the full catalog.
The default Postgres credentials (anvio/anvio) are placeholders for local use only. Always override POSTGRES_PASSWORD and JWT_SECRET before exposing any of these services beyond localhost.
Dockerfiles
All three Dockerfiles use the same multi-stage pattern: a base stage that activates pnpm@9.15.9 via Corepack, a deps stage that installs the workspace with --frozen-lockfile, a build stage that runs pnpm build --filter=@anvio/<app>..., and a lean node:20-alpine runner that only copies dist/, node_modules, and package.json.
# docker/Dockerfile.api (abridged)
FROM node:20-alpine AS base
RUN corepack enable && corepack prepare pnpm@9.15.9 --activate
WORKDIR /app
FROM base AS deps
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml* ./
COPY apps/api/package.json ./apps/api/
COPY packages/core/package.json ./packages/core/
# ...other workspace package.json files for correct dependency resolution
RUN pnpm install --frozen-lockfile
FROM deps AS build
COPY . .
RUN pnpm build --filter=@anvio/api...
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build /app/apps/api/dist ./dist
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/apps/api/package.json ./
EXPOSE 3000
CMD ["node", "dist/main.js"]Dockerfile.worker follows the identical shape (no exposed port — it's a background consumer), and Dockerfile.gateway exposes 3001 instead of 3000. Each Dockerfile only copies the package.json of packages that app actually depends on, so build layers stay minimal and cache-friendly per service.
Dev stack (docker/docker-compose.dev.yml)
Used for local development — start infra only, then run the Node apps yourself with pnpm dev:
docker compose -f docker/docker-compose.dev.yml up -d
pnpm db:migrate && pnpm db:seed
pnpm dev| Service | Image | Host port(s) | Notes |
|---|---|---|---|
postgres | postgres:16-alpine | 5432 | container name anvio-postgres |
redis | redis:7-alpine | 6379 | container name anvio-redis |
nats | nats:2.10-alpine (-js -m 8222) | 4222, 8222 | container name anvio-nats, monitoring on 8222 |
qdrant | qdrant/qdrant:v1.13.2 | 6333 | container name anvio-qdrant, behind the full profile |
Unlike the production file, every service here publishes its port to the host, since you're connecting from Node processes running outside Docker.
Qdrant is opt-in — it's gated behind profiles: [full] and only starts when you explicitly request that profile:
docker compose -f docker/docker-compose.dev.yml --profile full up -dThis matches Anvio's progressive-enhancement model: Level 1–2 workspaces use filesystem or SQLite memory and never need Qdrant; enable it only when you configure a vector-backed memory provider.
Checking service health
# API
curl http://localhost:3000/health
# NATS monitoring endpoint
curl http://localhost:8222/healthz
# Container-level health status
docker compose -f docker/docker-compose.yml psIf a container shows unhealthy, check its logs first:
docker compose -f docker/docker-compose.yml logs -f postgres
docker compose -f docker/docker-compose.yml logs -f apiSee Troubleshooting for the NATS-connection-refused and database-migration-failure runbooks.
Volumes
Both compose files declare named volumes for stateful services:
postgres_data→/var/lib/postgresql/dataredis_data→/dataqdrant_data→/qdrant/storage(dev only,fullprofile)
The production compose file does not persist a NATS volume — JetStream state lives in-container unless you extend the file with your own volume mount.
Runtime OAuth and Docker
Vendor OAuth (Claude Code, Cursor, Codex, Antigravity subscriptions) needs a browser, which containers don't have. Do not attempt interactive login inside a container. Instead, provision tokens on a machine with a browser and mount or inject them — see Runtime OAuth for the five supported patterns (provision-offline-and-mount, environment variables, headless vendor CLI, local runtime + API key, and mounting vendor credential directories for dev/staging only).
Last updated on