Skip to content

Docker Compose Deployment ​

Run GhostAI in containers with PostgreSQL and Redis. One command to start everything.

Architecture ​

Prerequisites ​

  • Docker 20.10+
  • Docker Compose 2.0+
  • 4 GB RAM minimum (8 GB recommended with local LLM)

Quick Start ​

bash
cd securechat
cp backend/.env.example backend/.env
# Edit backend/.env with your settings

docker compose up -d

Compose Files ​

FilePurposeCommand
securechat/docker-compose.ymlDev stack (PostgreSQL, no Redis)docker compose up -d
infrastructure/docker/docker-compose.aws.ymlFull stack (Postgres + Redis)docker compose -f infrastructure/docker/docker-compose.aws.yml up -d
infrastructure/docker/docker-compose.production.ymlProduction (Caddy HTTPS + Postgres + Redis)See Production
infrastructure/docker/docker-compose.observability.ymlOTel + Jaeger + Prometheus + GrafanaOverlay with -f
infrastructure/monitoring/docker-compose.monitoring.ymlPrometheus + Grafana + Loki + AlertmanagerStandalone monitoring

Example Configurations ​

A) Docker + Cloud LLM (Simplest) ​

bash
# --- Provider ---
LLM_PROVIDER=openai
OPENAI_API_KEY=sk-...
DEFAULT_MODEL=gpt-4o-mini

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

# --- Cache (Redis provided by compose) ---
REDIS_URL=redis://ghostai-redis:6379/0

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

B) Docker + Host Ollama ​

Run Ollama on the host machine (for Metal/CUDA access) and connect from containers.

bash
# --- Provider ---
LLM_PROVIDER=ollama
OLLAMA_BASE_URL=http://host.docker.internal:11434  # Reach host from container

# --- PII ---
PII_REFEREE_RUNTIME=ollama
PII_REFEREE_OLLAMA_URL=http://host.docker.internal:11434
PII_REFEREE_OLLAMA_MODEL=llama3.1:8b

Why not Ollama in a container?

Running Ollama on the host gives it direct GPU access (Metal on Mac, CUDA on Linux). Inside a container, GPU passthrough requires extra setup (NVIDIA Container Toolkit for CUDA, and Metal isn't available at all in Docker).

C) Docker + vLLM GPU Server ​

For GPU-rich servers running dedicated inference.

bash
LLM_PROVIDER=ollama
OLLAMA_BASE_URL=http://ghostai-ollama:11434

PII_REFEREE_RUNTIME=vllm
PII_REFEREE_VLLM_URL=http://ghostai-vllm:8000/v1
PII_REFEREE_VLLM_MODEL=meta-llama/Llama-3.1-8B-Instruct
PII_REFEREE_MAX_CONCURRENT=8

Base Image Pattern (Self-Hosted) ​

The backend image uses a two-layer build: a base image (heavy dependencies) and a thin app layer. For self-hosted Docker Compose deployments, pull the base image first to speed up builds:

bash
docker pull ghcr.io/ghostai/ghostai/backend-base:latest

Or set BASE_TAG in your .env file to pin a specific base version (e.g. base-abc123def456). The docker-compose.production.yml passes BASE_TAG, BASE_REGISTRY, and BASE_IMAGE as build args to the backend Dockerfile, so your compose build will use the specified base.

Deploy Script ​

The Docker deploy script wraps common operations:

bash
# Start
./infrastructure/scripts/targets/docker.sh up

# Status
./infrastructure/scripts/targets/docker.sh status

# Logs
./infrastructure/scripts/targets/docker.sh logs

# Update (rebuild + restart)
./infrastructure/scripts/targets/docker.sh update

# Rollback
./infrastructure/scripts/targets/docker.sh rollback

# Stop
./infrastructure/scripts/targets/docker.sh down

Monitoring ​

Use the Docker stress dashboard:

bash
python infrastructure/scripts/stress-dashboard-local.py
# Monitors container CPU/memory, Postgres connections, Redis stats

Or add the observability stack:

bash
docker compose -f infrastructure/docker/docker-compose.observability.yml up -d
# Jaeger:    http://localhost:16686
# Prometheus: http://localhost:9090
# Grafana:   http://localhost:3000

Troubleshooting ​

Docker socket path (macOS) ​

If Docker SDK can't connect, check your socket path:

bash
docker context inspect --format '{{.Endpoints.docker.Host}}'
# Might return: unix:///Users/you/.docker/run/docker.sock

Set DOCKER_HOST before running dashboards or scripts:

bash
export DOCKER_HOST=unix:///Users/you/.docker/run/docker.sock

Container can't reach Ollama on host ​

Use host.docker.internal (macOS/Windows) or 172.17.0.1 (Linux) instead of localhost in OLLAMA_BASE_URL.

Postgres connection refused ​

Wait a few seconds after docker compose up -- Postgres needs time to initialize. Check with:

bash
docker compose logs ghostai-postgres

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