Skip to content

Production Docker Deployment ​

Self-hosted production deployment with Caddy (automatic HTTPS via Let's Encrypt), PostgreSQL, and Redis.

Architecture ​

Prerequisites ​

  • Docker 20.10+ and Docker Compose 2.0+
  • A domain name pointing to your server
  • Port 80 and 443 open (for Let's Encrypt)
  • 4 GB RAM minimum (8 GB with local LLM)

Setup ​

1. Configure Environment ​

bash
cd securechat/backend
cp .env.example .env
bash
# --- Required ---
LLM_PROVIDER=openai                # or openrouter, ollama
OPENAI_API_KEY=sk-...
BASE_URL=https://chat.yourdomain.com
FRONTEND_URL=https://chat.yourdomain.com

# --- Database (from compose) ---
DATABASE_URL=postgresql://ghostai:${DB_PASSWORD}@ghostai-postgres:5432/ghostai

# --- Cache (from compose) ---
REDIS_URL=redis://ghostai-redis:6379/0

# --- Security ---
JWT_SECRET_KEY=<generate-a-random-64-char-string>
SESSION_SECRET=<generate-a-random-64-char-string>
PROVIDER_KEY_SECRET=<generate-a-random-64-char-string>

# --- PII ---
PII_ENABLE_AI_DETECTOR=true
PII_AI_MODEL=local
PII_REFEREE_RUNTIME=llama-cpp
PII_REFEREE_MODEL_GPU_LAYERS=0       # CPU in container
PII_REFEREE_WARMUP=true

2. Deploy ​

bash
docker compose -f infrastructure/docker/docker-compose.production.yml up -d

Caddy automatically obtains and renews TLS certificates from Let's Encrypt.

3. Verify ​

bash
curl https://chat.yourdomain.com/api/health

Service notice (optional) ​

You can show a deployment-wide message to all users (e.g. "System upgrade in progress", "PII detection temporarily degraded") in two ways:

  1. Environment variables — Set SERVICE_NOTICE and optionally SERVICE_NOTICE_SEVERITY (e.g. info, warning, error) in the backend environment, then restart/redeploy. Documented in backend/.env.example.
  2. Platform Admin UI — Platform admins can set or clear the notice from Platform Admin Console → Service notice without redeploying. The value stored in the database overrides the env when set.

The notice appears as a banner on the login page and as a dismissible dialog for logged-in users (dismissal is per-session, by notice text). Clearing the notice (empty string) removes it everywhere.

Adding Observability ​

Layer the observability stack on top of production:

bash
docker compose \
  -f infrastructure/docker/docker-compose.production.yml \
  -f infrastructure/docker/docker-compose.observability.yml \
  up -d

This adds:

ServicePortPurpose
OpenTelemetry Collector4317/4318Trace/metric collection
Jaeger16686Distributed tracing UI
Prometheus9090Metrics storage
Grafana3000Dashboards and alerting

Scaling ​

Horizontal Backend Scaling ​

yaml
# In docker-compose.production.yml
services:
  backend:
    deploy:
      replicas: 3

With multiple backend replicas, Redis handles session sharing and Caddy load-balances automatically.

GPU Inference (vLLM) ​

The production compose includes an optional vLLM service for GPU-accelerated PII inference:

bash
PII_REFEREE_RUNTIME=vllm
PII_REFEREE_VLLM_URL=http://ghostai-vllm:8000/v1
PII_REFEREE_MAX_CONCURRENT=8

Requires NVIDIA Container Toolkit and a GPU-enabled host.

Backup & Restore ​

bash
# Backup PostgreSQL
docker compose exec ghostai-postgres pg_dump -U ghostai ghostai > backup.sql

# Restore
cat backup.sql | docker compose exec -T ghostai-postgres psql -U ghostai ghostai

Base Image in Production Pipeline ​

CI builds the base and app images separately. The base image (heavy Python/system deps) is rebuilt weekly for security patches; the app image (thin code layer) is rebuilt on every push. For production deployments that use ECR, images are mirrored from GHCR to ECR. Both base and app images are scanned with Trivy for vulnerabilities before deployment.

Deploy Script ​

bash
./infrastructure/scripts/targets/docker.sh up       # Start
./infrastructure/scripts/targets/docker.sh update    # Rebuild + restart
./infrastructure/scripts/targets/docker.sh rollback  # Previous version
./infrastructure/scripts/targets/docker.sh validate  # Health checks

SOC 2 Type II Certified | BAA Available | HIPAA-Ready