Docker Compose

Run Spica in production on a single machine with Docker Compose, a MongoDB replica set and an nginx gateway.

This setup runs Spica on one machine: MongoDB, the API, the panel and an nginx gateway that serves the panel at / and the API at /api.

Files

compose.yaml
services:
  mongo:
    image: mongo:8.0
    command: ["--replSet", "rs0", "--bind_ip_all"]
    volumes:
      - mongo-data:/data/db
    healthcheck:
      test: ["CMD", "mongosh", "--quiet", "--eval", "try { rs.status().ok } catch (e) { rs.initiate({_id: 'rs0', members: [{_id: 0, host: 'mongo:27017'}]}).ok }"]
      interval: 5s
      timeout: 10s
      retries: 20
    restart: unless-stopped

  api:
    image: spicaengine/api:${SPICA_VERSION:-0.22.1}
    depends_on:
      mongo:
        condition: service_healthy
    environment:
      MASTER_KEY: ${SPICA_MASTER_KEY:?Set SPICA_MASTER_KEY}
      PASSPORT_DEFAULT_IDENTITY_PASSWORD: ${SPICA_ADMIN_PASSWORD:?Set SPICA_ADMIN_PASSWORD}
    command:
      - --port=4300
      - --database-uri=mongodb://mongo:27017/?replicaSet=rs0
      - --database-name=spica
      - --database-replica-set=rs0
      - --public-url=${SPICA_PUBLIC_URL:-http://localhost:8080/api}
      - --persistent-path=/data
    volumes:
      - spica-data:/data
    restart: unless-stopped

  panel:
    image: spicaengine/panel:${SPICA_VERSION:-0.22.1}
    restart: unless-stopped

  gateway:
    image: nginx:latest
    depends_on: [api, panel]
    ports:
      - "8080:80"
    volumes:
      - ./gateway.conf:/etc/nginx/conf.d/default.conf:ro
    restart: unless-stopped

volumes:
  mongo-data:
  spica-data:
gateway.conf
server {
  listen 80;
  client_max_body_size 35m;

  location / {
    proxy_pass http://panel:80/;
    proxy_set_header Host $host;
  }

  location /api/ {
    proxy_pass http://api:4300/;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 3600s;
  }
}
.env
SPICA_VERSION=0.22.1
SPICA_MASTER_KEY=<output of: openssl rand -hex 32>
SPICA_ADMIN_PASSWORD=<a strong password>
SPICA_PUBLIC_URL=https://admin.example.com/api

The trailing slashes in proxy_pass matter: the gateway strips /api before forwarding, so the API serves its routes at the root while --public-url keeps the /api suffix.

Start

Terminal
docker compose up -d
docker compose ps
curl http://localhost:8080/api/status/live
JSON
{"status": "ok"}

Open http://localhost:8080 and log in as spica with SPICA_ADMIN_PASSWORD.

Going to production

  • TLS. Put the gateway behind a TLS-terminating proxy or load balancer, or add a certificate to the nginx config. Set SPICA_PUBLIC_URL to the HTTPS URL.
  • Secrets. Keep .env out of git. Back up SPICA_MASTER_KEY: without it, encrypted data and secrets can't be read.
  • Backups. Back up the mongo-data volume (or use mongodump) and the spica-data volume, which holds uploaded files and function sources.
  • Upload size. Keep client_max_body_size in line with --storage-object-size-limit.
  • Options. Add any API option to the api service's command or as an environment variable, for example BUCKET_CACHE: "true".
  • Logs. docker compose logs -f api. Add --access-logs and --function-worker-log-output=database,stdout to send more to stdout.

PostgreSQL instead of MongoDB

Replace the mongo service with PostgreSQL, load pg_cron, and change the API's database options. These are the same settings spica project start --database-type postgresql uses:

YAML
  postgres:
    image: spicaengine/postgres:18-0.22.1
    command: ["postgres", "-c", "shared_preload_libraries=pg_cron", "-c", "cron.use_background_workers=on", "-c", "cron.database_name=spica"]
    environment:
      POSTGRES_USER: spica
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD}
      POSTGRES_DB: spica
    volumes:
      - postgres-data:/var/lib/postgresql
    restart: unless-stopped
YAML
    environment:
      POSTGRES_USERNAME: spica
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    command:
      - --port=4300
      - --database-type=postgresql
      - --database-uri=postgres://postgres:5432/spica
      - --public-url=${SPICA_PUBLIC_URL:-http://localhost:8080/api}
      - --persistent-path=/data

Upgrading

  1. Read the release notes of the new version.
  2. Back up the database and volumes.
  3. Change SPICA_VERSION and run docker compose pull && docker compose up -d.

Releases that change stored data ship a migration in the spicaengine/migrate image, which the Helm chart runs automatically. Check the release notes when you upgrade with Compose.