Docker Quickstart
Configure .env, generate all four cryptographic secrets, run Prisma migrations, and boot PostgreSQL 18, Redis 8.2, the API gateway, and BullMQ workers with Docker Compose.
KestrelMQ ships with a multi-stage Node 26 Alpine Dockerfile and a docker-compose.yml defining PostgreSQL 18 (postgres:18-alpine), Redis 8.2 (redis:8.2-alpine with --appendonly yes --maxmemory-policy noeviction), the API Gateway (api), and an isolated BullMQ worker (worker).
1. Generate Cryptographic Secrets
src/config/env.validation.ts validates all environment variables with Zod on startup and refuses to boot on any violation. Generate four secrets — ENCRYPTION_MASTER_KEY must be an exact 64-character hex string (32 bytes), and JWT_ACCESS_SECRET and JWT_REFRESH_SECRET must be distinct (minLength: 32):
openssl rand -hex 32 # APP_SECRET (>= 32 chars)
openssl rand -hex 32 # ENCRYPTION_MASTER_KEY (exact 64 hex chars · AES-256-GCM)
openssl rand -hex 32 # JWT_ACCESS_SECRET (>= 32 chars, distinct from refresh)
openssl rand -hex 32 # JWT_REFRESH_SECRET (>= 32 chars, distinct from access)Rotating ENCRYPTION_MASTER_KEY is destructive
Changing ENCRYPTION_MASTER_KEY makes every AES-256-GCM-encrypted record in integrations and inbound_sources unreadable. Re-create or re-enter external credentials after rotating a compromised master key.
2. Configure .env
Copy .env.example to .env and populate your container credentials, connection URLs, and cryptographic keys:
# Runtime & CORS
NODE_ENV=production
PORT=3000
CORS_ORIGINS=http://localhost:3001
# PostgreSQL 18 Container Settings (used by docker-compose.yml)
POSTGRES_USER=kestrelmq
POSTGRES_PASSWORD=replace-with-strong-postgres-password
POSTGRES_DB=kestrelmq
POSTGRES_PORT=5432
# Redis 8.2 Container Settings
REDIS_PORT=6379
# Application Connection URLs (validated by src/config/env.validation.ts)
POSTGRES_URL=postgresql://kestrelmq:replace-with-strong-postgres-password@localhost:5432/kestrelmq?schema=public
REDIS_URL=redis://localhost:6379
# Cryptographic Secrets (all 4 required; JWT secrets must differ)
APP_SECRET=d09c4a71e38f120b67e519da8c43f02b91e07c2a6d83f519c4b8e032d7f6a190
ENCRYPTION_MASTER_KEY=8f4c2e91b07d63a5c14e89f203d7a6bc4190e52f78d3c1a69b4e02f71c8a3d5e
JWT_ACCESS_SECRET=4b91e07c2a6d83f519c4b8e032d7f6a190c5e28d4b7a31f68e9c02b5d17a4e6c
JWT_REFRESH_SECRET=c37a91f04e82b6d5109c3f7e2a84d6b159e0c37a8d2f41b690c8e5a23f7d1b4e
JWT_ACCESS_TTL_SEC=900
JWT_REFRESH_TTL_SEC=604800
# Optional Rate-Limit & Backoff Tuning
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_FREE_MAX=60
RATE_LIMIT_PRO_MAX=3000
BILLING_MODE=self-hosted
BACKOFF_SCALE_FACTOR=1| Variable | Required | Default | Validation / Purpose |
|---|---|---|---|
POSTGRES_URL | Yes | — | postgres:// or postgresql:// URI (overridden inside docker-compose.yml for api/worker using POSTGRES_* vars). |
REDIS_URL | Yes | — | redis:// or rediss:// URI for BullMQ queues, rate limiters, and caches. |
APP_SECRET | Yes | — | Min 32 chars; application secret. |
ENCRYPTION_MASTER_KEY | Yes | — | Regex ^[0-9a-fA-F]{64}$ (32 bytes) for AES-256-GCM vault encryption. |
JWT_ACCESS_SECRET | Yes | — | Min 32 chars; signs operator access JWTs (JWT_ACCESS_TTL_SEC, default 900s / 15m). |
JWT_REFRESH_SECRET | Yes | — | Min 32 chars, must differ from JWT_ACCESS_SECRET; signs refresh JWTs (JWT_REFRESH_TTL_SEC, default 604800s / 7d). |
CORS_ORIGINS | No | http://localhost:3001 | Comma-separated list of allowed browser origins. |
RATE_LIMIT_WINDOW_MS | No | 60000 | Sliding-window duration in milliseconds. |
RATE_LIMIT_FREE_MAX | No | 60 | Max requests per window for FREE workspaces (PRO: 3000). |
BILLING_MODE | No | self-hosted | self-hosted lets operators switch a workspace between FREE (60 req/min, 10k deliveries/mo, 7-day retention) and PRO (3,000 req/min, 500k deliveries/mo, 30-day retention) from the dashboard; cloud disables self-serve plan switching (canSelfManagePlan: false) and defers to Cloud Billing. |
BACKOFF_SCALE_FACTOR | No | 1 | Multiplier applied to the 10s -> 1m -> 5m -> 30m -> 2h retry schedule. |
3. Start the Stack & Apply Migrations
In docker-compose.yml, the api and worker containers belong to profiles: ["prod", "full"] (running plain docker compose up -d starts only postgres and redis for local host development). Pass --profile prod to start all four containers, then apply Prisma 7 migrations:
git clone https://github.com/dmereiauron/kestrelmq.git
cd kestrelmq
cp .env.example .env
# Boot postgres, redis, api, and worker containers
docker compose --profile prod up -d --build
# Apply Prisma PostgreSQL schema migrations
docker compose --profile prod exec api npm run prisma:migrate:deployservices:
worker:
stop_grace_period: 30s
deploy:
replicas: 34. Verify GET /v1/health
Probe the public readiness endpoint (@Public()), which executes SELECT 1 on PostgreSQL and PING on Redis in parallel:
curl -s http://localhost:3000/v1/health | jq{
"status": "ok",
"timestamp": "2026-11-28T21:00:00.000Z",
"checks": {
"postgres": "up",
"redis": "up"
}
}If either dependency is down, GET /v1/health responds with 503 Service Unavailable (application/problem+json, detail: "Infrastructure health check failed for: ...") so Docker healthchecks and load balancers hold traffic until recovery.