Docker
This template runs the Civility server in one container with one volume. The volume is mounted at /data and holds the SQLite database (/data/civility.db) and the uploaded files (/data/blobs/).
Run only one container per volume. The SQLite file cannot be shared.
The template files are next to this page in the repository.
| File | What it does |
|---|---|
Dockerfile |
Deno on Alpine, with @civility/cli downloaded at the version in CIV_VERSION. |
entrypoint.sh |
Runs civ api start with the database and blobs under DATA_DIR. |
docker-compose.yml |
One service and one named volume. |
.env.example |
The environment variables, with comments. |
fly.toml |
Fly.io settings. Delete it if you do not use Fly.io. |
Start with Docker Compose
Copy the example environment file.
cp .env.example .envGenerate a secret.
openssl rand -hex 32Edit
.env. SetCIVILITY_AUTH_SECRETto the secret, and setCIVILITY_ADMIN_EMAILSto your email address.CIVILITY_AUTH_SECRET=<the secret from step 2> CIVILITY_ADMIN_EMAILS=you@example.orgBuild and start the container.
docker compose up -d --buildOpen http://localhost:8080/signup and create an account with the email from step 3. Then open http://localhost:8080/admin/.
The API reference is at http://localhost:8080/api/v1.
The server does not start without CIVILITY_AUTH_SECRET. Keep the same value for the life of the volume, and keep a copy outside the server.
For HTTPS, put a reverse proxy such as Caddy, nginx or Traefik in front of port 8080. The manual deployment page has a Caddy example.
Start with plain Docker
docker build -t civility-sqlite .
docker run -d --name civility -p 8080:8080 \
-v civility-data:/data \
-e CIVILITY_AUTH_SECRET='<your secret>' \
-e CIVILITY_ADMIN_EMAILS='you@example.org' \
--restart unless-stopped \
civility-sqlite
Environment variables
| Variable | Default | What it does |
|---|---|---|
CIVILITY_AUTH_SECRET |
None, required | Signs sessions and encrypts the credentials saved in the admin panel. |
CIVILITY_ADMIN_EMAILS |
None | Comma-separated emails. Accounts with these emails can open /admin after signing in. |
CIVILITY_ADMIN_TOKEN |
None | Token for scripts that call /admin. Generate one with openssl rand -hex 32. |
PORT |
8080 |
Port the server listens on inside the container. |
DATA_DIR |
/data |
Directory for civility.db and blobs/. It must be on the mounted volume. |
CIVILITY_BLOB_PATH |
$DATA_DIR/blobs |
Directory for uploaded files until you save a storage setting in /admin/storage. |
OTEL_DENO, OTEL_* |
None | Turn on OpenTelemetry. See Observability. |
docker-compose.yml passes only CIVILITY_AUTH_SECRET, CIVILITY_ADMIN_EMAILS and CIVILITY_ADMIN_TOKEN from .env into the container. To set CIVILITY_BLOB_PATH or the OTEL_* variables, add them under environment: in docker-compose.yml.
With Compose, the container always listens on 8080 and uses /data. PORT in .env changes the port on the host.
Email, blob storage, limits and tiers are settings in the admin panel. Until you set up email in /admin/email, the server prints messages to the container log and marks new accounts as verified.
Store uploaded files in a bucket
Open /admin/storage, choose S3-compatible, and enter the bucket details. The change does not move files that are already on the volume. See Blob storage for the steps, and the endpoint list for common providers.
Upgrade
Back up the volume.
Read Schema changes in the runbook.
In
Dockerfile, changeARG CIV_VERSION=to the new version.Rebuild and restart.
docker compose up -d --buildCheck that http://localhost:8080/health reports the new version.
The build does not accept packages published less than one day ago. To build a version released today, add the build argument MIN_DEP_AGE=0:
docker compose build --build-arg MIN_DEP_AGE=0
docker compose up -d
To roll back, set CIV_VERSION to the previous version and rebuild.
Back up
Everything is in the /data volume. Also keep a copy of .env, because a restored database needs the same CIVILITY_AUTH_SECRET.
These commands mount the volume of the Compose container into a temporary Alpine container. With plain Docker, replace "$(docker compose ps -aq civility)" with civility, and use docker stop civility and docker start civility.
With the server stopped:
docker compose stop
docker run --rm --volumes-from "$(docker compose ps -aq civility)" -v "$PWD":/backup alpine \
tar -czf /backup/civility-backup-$(date +%Y%m%d).tar.gz -C /data .
docker compose start
With the server running, copy the database with sqlite3, then archive the blobs:
docker run --rm --volumes-from "$(docker compose ps -aq civility)" -v "$PWD":/backup alpine \
sh -c 'apk add --no-cache sqlite && sqlite3 /data/civility.db ".backup /backup/civility.db"'
docker run --rm --volumes-from "$(docker compose ps -aq civility)" -v "$PWD":/backup alpine \
tar -czf /backup/civility-blobs.tar.gz -C /data blobs
Copy the backup files to another machine.
Restore
To test a backup without touching the live data, unpack it into a new volume and start a second container on another port. This uses the image from Start with plain Docker.
docker volume create civility-restore
docker run --rm -v civility-restore:/data -v "$PWD":/backup alpine \
tar -xzf /backup/civility-backup-20260101.tar.gz -C /data
docker run --rm -p 8081:8080 -v civility-restore:/data \
-e CIVILITY_AUTH_SECRET='<your secret>' \
civility-sqlite
Open http://localhost:8081/login, sign in as a known user, and check that their data and files are there.
To replace the live data with a backup:
docker compose stop
docker run --rm --volumes-from "$(docker compose ps -aq civility)" -v "$PWD":/backup alpine \
sh -c 'rm -rf /data/* && tar -xzf /backup/civility-backup-20260101.tar.gz -C /data'
docker compose start
Deploy to Coolify
- Create a new application from the repository that holds this directory. Choose the Dockerfile or Docker Compose build pack.
- Add a persistent storage volume mounted at
/data. Without it, the data is lost on every deploy. - Set
CIVILITY_AUTH_SECRETandCIVILITY_ADMIN_EMAILSin the environment variables. - Deploy and attach a domain.
Deploy to Fly.io
fly.toml describes one machine with one volume mounted at /data.
fly launch --no-deploy --copy-config
fly volumes create civility_data --region iad --size 3
openssl rand -hex 32
fly secrets set CIVILITY_AUTH_SECRET="<the value printed above>"
fly secrets set CIVILITY_ADMIN_EMAILS="you@example.org"
fly deploy
--size is in GB. Keep a copy of the secret, because Fly does not show it again.
Do not scale past one machine, because the volume belongs to one machine. To keep the volume small, store uploaded files in a bucket.
Related pages
- Hosting Civility: overview, start options and environment variables.
- Runbook: upgrade, rollback, backup and incident steps.
- Manual deployment: the same server under systemd and Caddy.