Skip to content

Run with Docker Compose

A persistent Compose deployment with a config file, a data volume, and credentials from the environment.

Updated

This Compose deployment keeps its data in a named volume, reads its credentials from a .env file, and runs in a hardened container. Use it once the throwaway quickstart container is no longer enough.

What you get

  • The published image from GHCR, with data in the logs named volume mounted at /data.
  • HTTP published on the host’s 127.0.0.1:3100 only.
  • A read-only root filesystem, a 256 MiB /tmp tmpfs, all Linux capabilities dropped, and a 35-second shutdown grace period.
  • Seven-day retention, a 20 GB size target per index, at most four indexes, and events archived to Parquet after one day.

Set it up

  1. Create a deployment directory

    mkdir logbrook && cd logbrook
  2. Write compose.yaml

    It runs the published ghcr.io/sandrinodm/logbrook:0.5.0 image and takes the credentials from .env. To run another release, a digest or your own build, set LOGBROOK_IMAGE in .env.

    compose.yamlyaml
    services:
      logbrook:
        image: ${LOGBROOK_IMAGE:-ghcr.io/sandrinodm/logbrook:0.5.0}
        ports:
          - "127.0.0.1:3100:3100"
        environment:
          LOGBROOK_BIND: 0.0.0.0:3100
          LOGBROOK_DATA_DIR: /data
          LOGBROOK_INGEST_TOKEN: ${LOGBROOK_INGEST_TOKEN:?Set a random ingestion token}
          LOGBROOK_READ_TOKEN: ${LOGBROOK_READ_TOKEN:?Set a different random read token}
          # LOGBROOK_ADMIN_TOKEN: ${LOGBROOK_ADMIN_TOKEN:?Set a random admin token}
          LOGBROOK_SOURCE: ${LOGBROOK_SOURCE:-apps}
          LOGBROOK_RETENTION_DAYS: ${LOGBROOK_RETENTION_DAYS:-7}
          LOGBROOK_MAX_SIZE_GB: ${LOGBROOK_MAX_SIZE_GB:-20}
          LOGBROOK_MAX_INDEXES: ${LOGBROOK_MAX_INDEXES:-4}
          LOGBROOK_INDEXES: ${LOGBROOK_INDEXES:-apps}
          LOGBROOK_ARCHIVE_AFTER_MS: ${LOGBROOK_ARCHIVE_AFTER_MS:-86400000}
          LOGBROOK_MAINTENANCE_INTERVAL_SECS: ${LOGBROOK_MAINTENANCE_INTERVAL_SECS:-60}
        volumes:
          - logs:/data
        read_only: true
        tmpfs:
          - /tmp:rw,noexec,nosuid,size=256m,mode=1777
        cap_drop:
          - ALL
        security_opt:
          - no-new-privileges:true
        restart: unless-stopped
        stop_grace_period: 35s
    
    volumes:
      logs:
  3. Create .env

    This generates both credentials and refuses to overwrite an existing file. Keep .env out of version control.

    (
      set -eu
      umask 077
      set -C
      cat > .env <<ENV
    LOGBROOK_INGEST_TOKEN=$(openssl rand -hex 32)
    LOGBROOK_READ_TOKEN=$(openssl rand -hex 32)
    ENV
    )

    Compose reads .env from the project directory. The ingestion token can only write and the read token can only query, so don’t swap them.

  4. Start it

    export COMPOSE_PROJECT_NAME=logbrook
    docker compose config --quiet
    docker compose up -d --wait --wait-timeout 120

    config --quiet validates the file without printing the expanded credentials. --wait returns once the image’s built-in health check passes.

  5. Send and search an event

    Load the credentials into your shell, then use the apps index that the template precreates.

    set -a; . ./.env; set +a
    
    curl --fail http://127.0.0.1:3100/indexes/apps/logs/ingest \
      -H "Authorization: Bearer $LOGBROOK_INGEST_TOKEN" \
      -H 'Content-Type: application/json' \
      --data "[{ \"time\": $(( $(date +%s) * 1000 )), \"level\": 30, \"service\": \"web\", \"msg\": \"hello from compose\" }]"
    
    docker compose exec -T logbrook logbrook query apps --since 1h
  6. Check that data persists

    docker compose restart logbrook
    docker compose exec -T logbrook logbrook query apps --since 1h

    The event is still there. docker compose down keeps the volume. docker compose down --volumes deletes it and all your logs.

Change the configuration

After you edit .env, recreate the container with docker compose up -d --wait. A plain restart does not reload the environment. Shell variables override .env, so unset stale ones first.

Common variables, all with defaults in the template:

Variable Default Meaning
LOGBROOK_SOURCE apps Source assigned to events written with the ingestion token.
LOGBROOK_INDEXES apps Comma-separated indexes to precreate. default always exists.
LOGBROOK_RETENTION_DAYS 7 Retention per index. Must exceed the archive age.
LOGBROOK_MAX_SIZE_GB 20 Disk-size target per index, in decimal GB. Not a hard quota.
LOGBROOK_MAX_INDEXES 4 Index slots, including default.
LOGBROOK_ARCHIVE_AFTER_MS 86400000 Event age before archiving to Parquet.
LOGBROOK_MAINTENANCE_INTERVAL_SECS 60 Seconds between maintenance passes.

To add an admin token for index administration, put LOGBROOK_ADMIN_TOKEN in .env, uncomment its line in compose.yaml, and recreate the service. Compose passes only mapped variables, so the token in .env alone does nothing. Keep the line commented out while you have no admin token: an empty token is invalid.

For separate ingestion sources, scoped readers, or per-index policies, mount a TOML file instead. See the configuration file.

Next steps

Type to search…

↑↓ navigate↵ selectEsc close