Skip to content

Docker Compose

The quickest way to run Klaxon locally or on a single server.

Quick Start

bash
docker compose up -d

This starts:

  • klaxon-server on port 3000
  • PostgreSQL 16 on port 5432 (user: klaxon, password: klaxon, db: klaxon)
  • Redis 7 on port 6379

docker-compose.yml

yaml
services:
  postgres:
    image: postgres:16-alpine
    ports:
      - "5432:5432"
    environment:
      POSTGRES_USER: klaxon
      POSTGRES_PASSWORD: klaxon
      POSTGRES_DB: klaxon
    volumes:
      - pgdata:/var/lib/postgresql/data

  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"

volumes:
  pgdata:

Adding the Server Container

To run the server as a Docker container (instead of cargo run):

yaml
services:
  server:
    image: ghcr.io/ottercoders/klaxon-server:latest
    ports:
      - "3000:3000"
    environment:
      DATABASE_URL: postgres://klaxon:klaxon@postgres:5432/klaxon
      REDIS_URL: redis://redis:6379
      CORS_ORIGINS: "*"
      RUST_LOG: info
    depends_on:
      postgres:
        condition: service_healthy

  worker:
    image: ghcr.io/ottercoders/klaxon-server:latest
    command: ["klaxon-server", "--worker"]
    environment:
      DATABASE_URL: postgres://klaxon:klaxon@postgres:5432/klaxon
      REDIS_URL: redis://redis:6379
      FCM_SERVER_KEY: ${FCM_SERVER_KEY:-}
    depends_on:
      postgres:
        condition: service_healthy

Building the Image Locally

bash
docker build -f crates/klaxon-server/Dockerfile -t klaxon-server .

The Dockerfile uses a multi-stage build: Rust compilation in rust:1.82-bookworm, runtime in debian:bookworm-slim.

Data Persistence

PostgreSQL data is stored in the pgdata named volume. To reset:

bash
docker compose down -v   # removes volumes
docker compose up -d     # fresh start