# Docker

> Run the gateway with Docker Compose, with Postgres, object storage and a local model.

Applies to: the Sypnia engine (open source, self-hosted).  
Source: https://ai.docs.sypnia.com/self-hosting/docker/

For agents: compose.yaml: ai (ghcr.io/sespinosav/sypnia-ai:1, port 8095, env SYPNIA_GATEWAY_*), db (postgres:16), optional minio for bodies/cache, optional local model server as an OpenAI-compatible provider (SYPNIA_GATEWAY_PROVIDERS=local=http://models:11434/v1). Health GET /v1/health; metrics GET /metrics (Prometheus) on the same port behind the root token. Sizing: 256 MB RAM handles hundreds of concurrent streams; Postgres small.

`compose.yaml`

```yaml
services:
  ai:
    image: ghcr.io/sespinosav/sypnia-ai:1
    ports: ["8095:8095"]
    environment:
      SYPNIA_GATEWAY_DATABASE_URL: postgres://sypnia:${DB_PASSWORD}@db:5432/sypnia_ai
      SYPNIA_GATEWAY_ROOT_TOKEN: ${SYPNIA_GATEWAY_ROOT_TOKEN}
      SYPNIA_GATEWAY_OPENROUTER_KEY: ${OPENROUTER_API_KEY}
      SYPNIA_GATEWAY_PROVIDERS: local=http://models:11434/v1
      SYPNIA_GATEWAY_STORAGE_URL: s3://sypnia-ai?endpoint=http://storage:9000
      SYPNIA_GATEWAY_OTLP_ENDPOINT: https://telemetry.ingest.sypnia.com/v1/otlp
      SYPNIA_GATEWAY_OTLP_HEADERS: Authorization=Bearer ${SYPNIA_PROJECT_KEY}
    depends_on: [db, storage]
  db:
    image: postgres:16
    environment: { POSTGRES_USER: sypnia, POSTGRES_PASSWORD: "${DB_PASSWORD}", POSTGRES_DB: sypnia_ai }
    volumes: [db:/var/lib/postgresql/data]
  storage:
    image: minio/minio
    command: server /data
    volumes: [storage:/data]
volumes: { db: {}, storage: {} }
```

- **Object storage is optional.** Without it, routes cannot keep questions and answers, and the response cache stays off.
- **A local model** is any server that speaks the OpenAI API; in routes it is `local/<model name>`.
- **Health** is `GET /v1/health`; metrics for Prometheus are at `GET /metrics`, with the root token.
- **Size.** The gateway needs about 256 MB of memory for hundreds of answers streaming at once; most of a call's time is the model's.

Run migrations on start with `SYPNIA_GATEWAY_AUTO_MIGRATE=true`, or once with `docker compose run ai sypnia-ai migrate`.
