# TrailBase Docker Minimal, production-minded Docker images for [TrailBase](https://trailbase.io/), shipped in two flavors: - **Rootless** (default, recommended) โ€” runs as a dedicated non-root `trailbase` user. - **Root** โ€” runs as `root`, for environments where that's simpler or required. Both use a multi-stage Alpine build that downloads a pinned TrailBase release (the static musl `trail` binary plus the prebuilt auth UI WASM component), **verifies their SHA-256 digests**, and ships only those files in the runtime image. An entrypoint script optionally bootstraps an admin user on every start. ## Features - ๐Ÿชถ Small Alpine-based image, multi-stage build (only the `trail` binary and auth UI in the final layer). - ๐Ÿ”’ SHA-256 verification of the downloaded release during build (digests pinned in the Dockerfiles, refreshed by `bump.sh`). - ๐Ÿ‘ค Rootless and root variants, kept isolated via distinct Compose project names. - ๐ŸŒฑ Idempotent admin bootstrap โ€” creates (or promotes) the admin only if needed. - ๐Ÿงน Takes over the auto-generated `admin@localhost` account on first start, so no stray default admin remains. - ๐Ÿ—๏ธ Multi-arch (`amd64` / `arm64`) via buildx `TARGETARCH`. - โค๏ธ Built-in `HEALTHCHECK` hitting `/api/healthcheck`. - ๐Ÿ›‘ `tini` as PID 1 for clean signal handling. - ๐Ÿ’พ Persistent `traildepot` volume for databases, config, uploads, secrets and backups. ## Requirements - Docker with Compose v2 (`docker compose`). - Optionally buildx for multi-arch builds. ## Quick start ```bash # 1. Configure cp .env.example .env # edit .env โ€” at minimum set TB_ADMIN_EMAIL and TB_ADMIN_PASSWORD to bootstrap an admin # 2. Build & run (rootless variant, default) docker compose -f docker-compose.rootless.yml up -d --build # 3. Open the admin UI # http://localhost:4000/_/admin/ ``` For the root variant: ```bash docker compose -f docker-compose.root.yml up -d --build ``` The two stacks use separate Compose project names (`trailbase` vs `trailbase-root`), so their containers and volumes stay isolated. Both default to port `4000`; set a different `TB_PORT_ROOT` to run them side by side. ## Configuration Copy `.env.example` to `.env` and adjust. Compose reads `.env` automatically; **keep it out of version control** (already covered by `.gitignore`). | Variable | Default | Description | |---|---|---| | `TB_VERSION` | `0.36.1` | TrailBase release to build (published tag without the leading `v`). Change it with `bump.sh`. | | `CONTAINER_NAME` | `trailbase` | Base name for the container. | | `TB_PORT` | `4000` | Port for the rootless stack (used inside the container and for the host mapping). | | `TB_PORT_ROOT` | `4000` | Port for the root stack. | | `TB_DATA` | `traildepot` | Depot storage for the rootless stack: a named volume (default) or a host path for a bind mount (must contain a `/`, e.g. `./traildepot`). | | `TB_DATA_ROOT` | `traildepot` | Depot storage for the root stack. Use a different host path than `TB_DATA` so the stacks don't share a depot. | | `TB_PUBLIC_URL` | *(empty)* | Public URL of the instance, passed as `--public-url`. Needed for auth email links and OAuth redirects. | | `TB_ADMIN_EMAIL` | *(empty)* | Admin email to bootstrap. Leave blank to skip bootstrapping. | | `TB_ADMIN_PASSWORD` | *(empty)* | Admin password. Required only when the user doesn't yet exist. | ### Admin bootstrap On every start the entrypoint looks up `TB_ADMIN_EMAIL` in `traildepot/data/main.db`: - **admin exists** โ†’ nothing happens (`TB_ADMIN_PASSWORD` is ignored). - **user exists but is not an admin** โ†’ it is promoted with `trail admin promote`. - **missing** โ†’ the admin is created with `TB_ADMIN_PASSWORD` (required in that case, otherwise the container exits with an error): - **fresh depot (first start)** โ†’ TrailBase auto-creates `admin@localhost` with a random password; the entrypoint takes that account over by renaming it to `TB_ADMIN_EMAIL` (`trail user change-email`) and setting `TB_ADMIN_PASSWORD` (`trail user change-password`). No stray default admin is left behind. - **existing depot** โ†’ the user is created with `trail user add` and promoted. โš ๏ธ `trail user add` is broken in TrailBase 0.36.x (it inserts into a column a migration removed); in that case the container exits with a hint โ€” create the user in the admin UI and restart to have it promoted. - `TB_ADMIN_EMAIL` blank โ†’ bootstrap is skipped entirely. Passwords set through the CLI are not checked against TrailBase's password policy. Without bootstrapping, TrailBase's own `admin@localhost` account remains; find its random password in the first start's log: ```bash docker compose -f docker-compose.rootless.yml logs trailbase | grep -A2 "Created new admin user" ``` ### TrailBase config overrides TrailBase stores its settings in `traildepot/config.textproto` (editable from the admin UI). Any field can be overridden with a `TRAIL_` environment variable โ€” add them under `environment:` in the Compose file, e.g. `TRAIL_SERVER_APPLICATION_NAME: "My App"`. Secrets such as OAuth client secrets or SMTP passwords belong in `traildepot/secrets/` or in those environment variables, never in the config file. TrailBase has no equivalent of PocketBase's settings-encryption key; protect the `traildepot` volume instead. ## Running CLI commands Any arguments given to the container are forwarded to `trail --depot=/app/traildepot` instead of starting the server: ```bash # against the running container docker compose -f docker-compose.rootless.yml exec trailbase /app/trail --depot=/app/traildepot admin list # as a one-off container (stop the server first for write commands) docker compose -f docker-compose.rootless.yml run --rm trailbase user change-password admin@example.com 'new-secret' ``` ## Data persistence Everything TrailBase writes lives in `/app/traildepot`, backed by the named Docker volume `traildepot`: ``` traildepot/ โ”œโ”€โ”€ config.textproto # settings โ”œโ”€โ”€ data/ # main.db, logs.db, session.db, queue.db โ”œโ”€โ”€ migrations/ # SQL migrations โ”œโ”€โ”€ uploads/ # file uploads โ”œโ”€โ”€ secrets/ # keys and secrets โ”œโ”€โ”€ backups/ โ””โ”€โ”€ wasm/ # WASM components (auth UI baked into the image) ``` Data survives container recreation. To develop migrations against the running instance, uncomment the bind mount in the Compose file: ```yaml # - ./migrations:/app/traildepot/migrations ``` You can also bake `migrations` into the image by uncommenting the corresponding `COPY` line in the Dockerfile. To keep the depot in a host folder instead, set `TB_DATA` (or `TB_DATA_ROOT` for the root stack) to a path, e.g. `TB_DATA=./traildepot`. Any value without a `/` is treated by Compose as a volume name, and only `traildepot` is declared, so use a path for anything else. > **Note:** if you switch the named volume to a host bind mount (e.g. `TB_DATA=./traildepot`) with the rootless image, make sure the host folder exists and is writable by the container user, or TrailBase fails with `PermissionDenied`. A bind mount also hides the auth UI component baked into the image; reinstall it with `trail components add trailbase/auth_ui`. ## Building for a specific version or architecture ```bash # multi-arch build with buildx docker buildx build \ --platform linux/amd64,linux/arm64 \ --build-arg TB_VERSION=0.36.1 \ -f Dockerfile.rootless \ -t trailbase:0.36.1 . ``` The Dockerfiles pin the SHA-256 digests of one release, so building another version with `--build-arg TB_VERSION=...` alone fails checksum verification. Use `bump.sh`. ### Bumping the pinned version `bump.sh` rewrites the version in every file that pins it (`.env.example`, both Dockerfiles, both Compose files, and this README), fetches the new release's asset digests from the GitHub API into both Dockerfiles, and commits the result: ```bash ./bump.sh ``` Pass `--no-commit` to rewrite the files without committing. The script refuses to run on a dirty working tree when it would commit, so unrelated changes don't end up in the bump. When adding a new file that pins the version, add it to the `FILES` list at the top of the script. ## Health check Both images define a `HEALTHCHECK` that polls `http://127.0.0.1:${TB_PORT}/api/healthcheck`. Check status with: ```bash docker ps docker inspect --format '{{.State.Health.Status}}' trailbase ``` ## Managing the stack ```bash # logs docker compose -f docker-compose.rootless.yml logs -f # stop docker compose -f docker-compose.rootless.yml down # stop and remove the data volume (destroys the database!) docker compose -f docker-compose.rootless.yml down -v ``` ## Project layout ``` . โ”œโ”€โ”€ Dockerfile.rootless # non-root image (default) โ”œโ”€โ”€ Dockerfile.root # root image โ”œโ”€โ”€ docker-compose.rootless.yml # rootless stack (project: trailbase) โ”œโ”€โ”€ docker-compose.root.yml # root stack (project: trailbase-root) โ”œโ”€โ”€ entrypoint.rootless.sh # bootstrap + run (non-root) โ”œโ”€โ”€ entrypoint.root.sh # bootstrap + run (root) โ”œโ”€โ”€ bump.sh # bump pinned version + digests โ”œโ”€โ”€ .env.example # configuration template โ”œโ”€โ”€ .gitattributes # forces LF endings for shell/Docker files โ””โ”€โ”€ .gitignore ``` > **Note:** shell scripts and Dockerfiles must keep LF line endings (enforced via `.gitattributes`) โ€” CRLF endings break execution inside the Linux container. ## License TrailBase is distributed under its own [license](https://github.com/trailbaseio/trailbase/blob/main/LICENSE). This repository contains only the Docker packaging.