This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Self-Hosting and Deployment
ContactSheet ships as Docker Compose with three services — backend (FastAPI), frontend (Next.js), and nginx (routing + static files). State persists to two host directories: ./data and ./uploads.
On a Synology NAS? See Deploying on a Synology NAS for a click-by-click guide using DSM's Container Manager and built-in reverse proxy — no command line.
Quick start
git clone https://github.com/nielsfranke/contactsheet.git contactsheet
cd contactsheet
cp .env.example .env
docker compose up -d
Open http://localhost:8765. On a fresh install you land on the first-run setup wizard — create your admin username and password in the browser. No secrets are required in .env.
Non-interactive setup: set
ADMIN_PASSWORD(and optionallySECRET_KEY) in.envbefore the first boot and setup completes automatically.SECRET_KEYis auto-generated and persisted to the database if you leave it blank.
Database migrations run automatically on container start, so there's nothing to run by hand.
Run pre-built images (no local build)
docker compose up -d builds from source. To skip the build and pull the published multi-arch images (linux/amd64 + linux/arm64) instead:
docker compose pull
docker compose up -d
| Image | Tags |
|---|---|
ghcr.io/nielsfranke/contactsheet-backend |
latest, plus a tag per release (e.g. 1.14.0) |
ghcr.io/nielsfranke/contactsheet-frontend |
latest, plus a tag per release (e.g. 1.14.0) |
Pin a release or point at a different registry via .env — e.g. TAG=1.13.1, or REGISTRY=ghcr.io/<user> once mirrored to another host. The nginx service uses the stock upstream image (pinned to a minor version, nginx:1.27-alpine).
Storage layout
Data is split across two directories so you can back them up — or place them on different disks — independently:
| Directory | Contents |
|---|---|
./data |
SQLite database, settings, branding & watermark assets, generated ZIP exports and backups, plus the temporary spool for incoming uploads (exports/.tmp) |
./uploads |
the photos & videos (plus generated thumbnails / watermark cache) |
services:
backend:
build: { context: ., target: backend }
volumes:
- ./data:/data
- ./uploads:/data/uploads
environment:
SECRET_KEY: "${SECRET_KEY:-}"
ADMIN_USERNAME: "${ADMIN_USERNAME:-admin}"
ADMIN_PASSWORD: "${ADMIN_PASSWORD:-}"
COOKIE_SECURE: "${COOKIE_SECURE:-false}"
restart: unless-stopped
frontend:
build: { context: ., target: frontend }
depends_on: [backend]
restart: unless-stopped
nginx:
image: nginx:1.27-alpine
ports: ["${PORT:-8765}:80"]
volumes:
- ./uploads:/data/uploads:ro
- ./data/branding:/data/branding:ro
depends_on: [backend, frontend]
restart: unless-stopped
- nginx is the only published port; it routes
/apito the backend, serves/uploadsand/brandingstraight from disk, and streams large uploads. Everything else goes to the frontend. - No database server — SQLite lives in the
./datadirectory. DB_URL/UPLOAD_DIRaren't listed because they already default to/data/...inside the container.- Uploads are spooled on the data volume, not in the container's
/tmp: request bodies are buffered in./data/exports/.tmpbefore processing, so a multi-GB PSB can't fill a small container filesystem. Leave room for the largest upload you expect on the./datadisk. - The shipped compose file also rotates every container's logs (3 × 10 MB) and sets memory ceilings, see Resources & health.
Permissions
The API serves as a non-root user (UID 1001). The backend starts as root only to fix ownership of the /data + /data/uploads mount points, then drops to UID 1001 — so even a bind mount pointed at an existing directory on another disk (e.g. /mnt/Media/ContactSheet) becomes writable automatically; no manual chown needed.
On the same start it also restores missing write permissions: some NAS systems (seen on UGREEN UGOS) re-apply share permissions on every boot and strip the write bit from the upload folder — even the owner's — so uploads failed with Permission denied. The backend puts owner-write back on the data folders and on anything under uploads it owns but can't write, and logs how many paths it repaired (Restored owner write permission on N path(s)…). A periodic permission-fix script isn't needed, so the disks can spin down.
The only exception is if you pin a non-root user yourself (a user: override in docker-compose.yml): then the self-fix is skipped and you must make the directory writable by that UID, e.g. sudo chown -R 1001:1001 /mnt/Media/ContactSheet or setfacl -R -m u:1001:rwx /mnt/Media/ContactSheet.
Environment variables
All are optional — leave them blank to use the setup wizard. Set them in .env.
| Variable | Default | Description |
|---|---|---|
SECRET_KEY |
auto-generated | JWT signing key; persisted to the DB if unset. Generate one with openssl rand -hex 32. |
ADMIN_USERNAME |
admin |
Admin login username (or chosen in the wizard). |
ADMIN_PASSWORD |
wizard | Admin password; if unset you create it on first run in the browser. |
PORT |
8765 |
Host port nginx is exposed on. |
COOKIE_SECURE |
false |
Forces the admin cookie to be flagged Secure. Usually unnecessary: the cookie is flagged Secure automatically whenever the request arrives over HTTPS (your proxy's X-Forwarded-Proto). |
TRUSTED_PROXY_HOPS |
1 |
Number of trusted reverse proxies in front of the app. 1 = the bundled nginx only. Set 2 when an extra proxy fronts the stack (e.g. Nginx Proxy Manager / Caddy → bundled nginx) so rate limiting and the activity log see the real client IP, not the proxy's. Set 0 if the app is directly exposed with no proxy at all — forwarded headers are then ignored entirely, so a spoofed X-Forwarded-For can't slip past rate limiting. |
ACCESS_TOKEN_TTL |
86400 (24h) |
Admin session length for a normal login. |
REMEMBER_TOKEN_TTL |
2592000 (30d) |
Admin session length when "Remember me" is checked. |
REGISTRY / TAG |
ghcr.io/nielsfranke / latest |
Image source when pulling pre-built images. |
BACKEND_INTERNAL_URL |
http://backend:8000 |
How the frontend reaches the backend container-to-container to render link previews. Defaults to the compose service name — only set it if you renamed the backend service. |
ML_SERVICE_URL |
unset | URL of the optional semantic-search sidecar. Set to http://ml:8001 to enable content search. Empty = feature off. |
ML_QUANTIZED |
1 |
Sidecar only: INT8 model (smaller/faster on CPU); 0 for full precision. |
ML_THREADS |
4 |
Sidecar only: CPU inference threads. Keep below your core count so indexing yields to serving. |
Tuning limits
These have sensible defaults and only need touching on unusual hardware or workloads:
| Variable | Default | Description |
|---|---|---|
MAX_UPLOAD_BYTES |
314572800 (300 MB) |
Per-file ceiling for regular photos (JPEG/PNG/WebP/RAW). |
MAX_DOCUMENT_BYTES |
8589934592 (8 GB) |
Per-file ceiling for Photoshop .psd/.psb and TIFF working files. Your proxy must allow at least this too — see below. |
MAX_IMAGE_PIXELS |
250000000 (250 MP) |
Resolution ceiling per photo; also the decompression-bomb guard. Covers 150 MP medium format and big panorama stitches. Lower it on a memory-constrained host (decoding costs roughly width × height × 3 bytes per worker). Public client uploads keep their own, much stricter cap regardless. |
CLIENT_UPLOAD_MAX_FILE_BYTES |
26214400 (25 MB) |
Per-file ceiling for client (guest) uploads. Lifted per gallery by Allow large files. |
CLIENT_UPLOAD_MAX_TOTAL_BYTES |
262144000 (250 MB) |
Per-request total for client uploads (the browser splits bigger selections). Dropped by Allow large files. |
CLIENT_UPLOAD_MAX_PIXELS |
50000000 (50 MP) |
Resolution ceiling for client uploads. Allow large files raises it to MAX_IMAGE_PIXELS. |
CLIENT_UPLOAD_MIN_FREE_BYTES |
5368709120 (5 GB) |
Free space every client upload must leave on the data and media volumes; otherwise it's refused ("out of storage space") before being written, so visitors can never fill the disk the database lives on. |
DB_POOL_SIZE / DB_MAX_OVERFLOW |
20 / 40 |
Database connection pool. Sized for upload bursts; raise only if you see QueuePool limit … reached in the logs. |
BACKEND_MEMORY_LIMIT / FRONTEND_MEMORY_LIMIT / NGINX_MEMORY_LIMIT / ML_MEMORY_LIMIT |
6g / 1g / 512m / 4g |
Per-container memory ceilings in the shipped docker-compose.yml. Raise the backend's for very large PSB/TIFF working files; lower them on a small box. |
Everything else (video size, thumbnail sizes, worker counts) has defaults in backend/app/config.py and can be overridden via the same .env.
Behind a reverse proxy (HTTPS)
Run something like Nginx Proxy Manager or Caddy in front of the container:
-
Point a proxy host at your Docker host on the
PORTyou exposed (default8765). -
Enable WebSockets (required for live updates) and terminate SSL there (e.g. Let's Encrypt).
-
Make sure the proxy sends
X-Forwarded-Proto(Nginx Proxy Manager and Caddy do by default): the admin cookie is then flagged Secure automatically.COOKIE_SECURE=truein.envforces it regardless. -
Enable HSTS at the proxy once HTTPS works, so browsers refuse to ever talk to the site over plain HTTP: add the response header
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload. Set this at the edge proxy that terminates TLS, not in the app — ContactSheet also supports plain-HTTP LAN deployments, so the bundled stack deliberately doesn't send HSTS itself. In Nginx Proxy Manager it's the proxy host's SSL → "HSTS Enabled" toggle; in Caddy it's on by default for HTTPS sites. (Only addpreloadif you intend to submit the domain to the HSTS preload list — it's effectively permanent.) -
Set
TRUSTED_PROXY_HOPS=2in.env. Your proxy is a second hop in front of the bundled nginx, so without this the activity log and rate limiter see your proxy's IP for every visitor instead of the real client. (Leave it at the default1if nothing fronts the bundled nginx.) -
If clients reach galleries on a different domain than your admin host, set the Public base URL in Settings → General so share links use the right origin. See Sharing and Access.
-
Allow large uploads at your proxy. ContactSheet accepts Photoshop
.psd/.psband TIFF files up to 8 GB (configurable viaMAX_DOCUMENT_BYTES; regular photos stay at 300 MB). The bundled nginx already permits this, but a reverse proxy in front will reject the upload first unless you raise its body-size limit too:- Caddy — no default request-body limit, so usually nothing to do. Only if you explicitly set
request_body { max_size … }for the site, raise it (e.g.max_size 8GB). - Nginx Proxy Manager — open the proxy host → Advanced tab → add
client_max_body_size 8g;. - plain nginx —
client_max_body_size 8g;in the site'sserver/locationblock.
The same applies to client uploads in galleries with Allow large files on — they use the same upload route and limits.
Multi-gigabyte uploads also need generous timeouts; the bundled nginx already uses 1800s, so match that at the edge if your proxy has a short default.
Header, cover, watermark and logo uploads are a separate route with its own limit — 100 MB, so a full-resolution developed JPEG can be dropped in as a gallery header without shrinking it first. The bundled nginx allows
110mthere; if a proxy fronts the stack, make sure it permits at least 100 MB on/api/galleries/*/header-image,/cover-image,/watermarkand/api/admin/settings/logotoo (in Nginx Proxy Manager the same Advanced box covers it).Normal photo uploads need nothing special. A large drag-and-drop batch is split client-side into byte-bounded parts that upload sequentially, so even a multi-GB folder of ordinary JPEGs stays well under any realistic proxy limit. The big numbers above matter only for single huge files (PSD/PSB/TIFF) and for backup/restore archives.
- Caddy — no default request-body limit, so usually nothing to do. Only if you explicitly set
Updating
docker compose pull # if you run pre-built images
docker compose up -d
Or rebuild from source:
git pull
docker compose up -d --build
Migrations run on start, so an update applies any new schema automatically.
Upgrading from a single-volume install? The media moved out of
./data/uploadsinto its own./uploadsdirectory. Do the one-time move while the stack is stopped:docker compose down mv data/uploads uploads docker compose up -d(
./datakeeps the database, settings, branding and watermarks.)
Upgrading from < 1.2.0 with your own
docker-compose.yml? Link previews need the frontend to reach the backend container directly. Recent images default this tohttp://backend:8000, so a standard stack works automatically. Only if you renamed the backend service do you need to add it explicitly to thefrontendservice:frontend: environment: BACKEND_INTERNAL_URL: "http://<your-backend-service>:8000"Then
docker compose up -d frontend. Test with a fresh share link — chat apps cache the old (empty) preview.
Upgrading to 1.3.0 with a host-mounted
nginx.conf? The new backup/restore feature moves multi-gigabyte archives, which need a raised request-body limit. The bundlednginx.confalready includes it — but if you mount your own config, add this block (above the generallocation /api/) or backup download and restore upload will fail:location ~ ^/api/admin/settings/(backup|restore) { client_max_body_size 2g; proxy_request_buffering off; proxy_pass http://backend:8000; 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_read_timeout 1800s; proxy_send_timeout 1800s; }Pulling the new images alone won't touch a host-mounted file. The schema migration that ships with 1.3.0 applies automatically on start.
Upgrading to 1.6.8 with a host-mounted
nginx.conf? The PSD/PSB/TIFF upload limit rose to 8 GB. The bundlednginx.confnow setsclient_max_body_size 8gon the image-upload route — but if you mount your own config, raise that limit there yourself. Gotcha: a single-file bind mount is pinned to the file's inode, so editing the file on disk (or agit pullthat rewrites it) is not picked up by a reload — recreate the container to rebind it:docker compose up -d --force-recreate nginxAlso make sure any reverse proxy in front (Caddy / Nginx Proxy Manager / nginx) allows ≥ 8 GB — see Behind a reverse proxy above. No schema migration in 1.6.8.
Upgrading to 1.7.0 with a host-mounted
nginx.conf? Gallery header and cover uploads went from ~10 MB to 100 MB. The bundlednginx.confnow setsclient_max_body_size 110mon the header/cover/watermark/logo route — but a host-mounted config isn't touched by pulling new images, and a single-file bind mount is pinned to the file's inode, so editing it (or agit pullthat rewrites it) needs a container recreate:docker compose up -d --force-recreate nginxIf a reverse proxy fronts the stack, raise its body-size limit to ≥ 100 MB on those paths too. Everything else in 1.7.0 (per-mode sub-gallery templates, migration 0045) applies automatically on start.
Upgrading to 1.9.0 — a new link appears on your client galleries. Every public gallery now carries a small legal strip with a Source link (the AGPL obligation to offer the running source to the people using it — see Branding and Settings). It can't be switched off; if you run a modified build, point Settings → General → Source code URL at your own repository. The optional Support link next to it stays off on upgraded instances. Migration 0047 applies automatically; no config change.
Upgrading to 1.9.2 with a host-mounted
nginx.conf? Two fixes in that release live innginx.conf, so pulling images alone won't deliver them:
- the static
/uploads/and/branding/locations were silently dropping theX-Frame-OptionsandReferrer-Policysecurity headers (nginx header inheritance is all-or-nothing, so each location must repeat the full set), and- the auth rate-limit zone was far too tight behind a fronting proxy, where every visitor collapses into one bucket — a handful of clients entering a gallery password together got bare 503s.
Take the new file from the repo and recreate the container (a single-file bind mount is pinned to the inode, so an edit alone isn't picked up):
docker compose up -d --force-recreate nginxAlso in 1.9.2:
TRUSTED_PROXY_HOPS=0is honoured again, so if you run the app directly exposed with no proxy, set it — forwarded headers are now trusted only when a proxy is actually declared. The default (1, the bundled nginx) and the shipped Compose setup are unaffected.
Upgrading to 1.9.4 / 1.10.0 with a host-mounted
nginx.conf? Several fixes live innginx.conf. 1.9.4:/uploads/and/branding/send a singleCache-Controlheader (and a 404 there no longer picks up a 30-day cache). 1.10.0: it passes on your edge proxy'sX-Forwarded-Proto(so the admin cookie is flagged Secure behind Nginx Proxy Manager withoutCOOKIE_SECURE), drops the query string from its access log (gallery tokens travel as?token=), streams ZIP downloads unbuffered, and sends thescript-src 'none'CSP on/uploads/. Take the new file from the repo and recreate the container:docker compose up -d --force-recreate nginxThe compose file also gained log rotation and memory ceilings (see Resources & health) — copy those over if you maintain your own. Migration 0048 applies automatically.
Upgrading to 1.13.0 — restoring a backup signs everyone out. A restore no longer revives sessions you ended with Sign out everywhere or a password change after the backup was made; every restore now ends all admin sessions. The job-based public ZIP API (
POST /api/public/g/{token}/zipand its status/download endpoints) was removed — the gallery itself only ever used the streaming download, so this only matters if you scripted against it. No migration.
Backups
ContactSheet has a built-in full-instance backup & restore — the simplest option for most setups.
In the app: go to Settings → General → Backup & restore. Create backup builds a single archive that you can download — Full (database plus original photos, branding and watermarks) or Settings & metadata only (no photos, for when they're backed up elsewhere). Backups run as a background job (like ZIP export), and a full backup can optionally leave out the generated previews for a smaller archive (they're rebuilt after a restore). The database is captured safely with SQLite's VACUUM INTO (never a naive copy of the live WAL file), and photos uploaded while the backup is running are included too.
Restore from backup… uploads an archive and swaps it into place. It keeps a rollback copy, refuses an archive made by a newer version (older ones are migrated forward), and signs everyone out — you included — so sign in again afterwards. While it runs, the instance answers with a short "restore in progress" message; if uploads or exports are still busy after 30 seconds, the restore is refused so you can retry once they've finished. Only one restore can run at a time.
Archives are plaintext. They contain the admin password hash and the instance secret key, so store them somewhere private. (Built-in encryption is a planned follow-up.)
Large instances — restore from the command line instead of the browser (no upload size limit, blessed for big libraries):
docker compose exec backend python -m app.restore /data/exports/backups/<archive>.tar
Manual snapshot (alternative): you can still just copy the two host directories — ./data (database, branding, watermarks) and ./uploads (originals + previews). For a consistent database copy while running, stop the stack first (docker compose down), since the DB runs in WAL mode and a naive copy mid-write can miss recent changes. Restoring is putting both directories back and docker compose up -d.
Resources & health
The compose file sets generous memory ceilings — backend 6g (decoding a 250 MP original takes about 1 GB), frontend 1g, nginx 512m, the optional ML sidecar 4g — overridable in .env via BACKEND_MEMORY_LIMIT, FRONTEND_MEMORY_LIMIT, NGINX_MEMORY_LIMIT and ML_MEMORY_LIMIT. Container logs are rotated (3 files × 10 MB each). Every service has a healthcheck, and the frontend and nginx wait for the backend to be healthy before starting.
GET /api/health is the liveness check (it also reports the version); GET /api/health/ready reports the database, migrations, storage and ML sidecar separately and returns 503 only when the database is down.
Optional: semantic content search
Content search lets you find photos by what's in them ("car at sunset"), within a gallery or across your whole library. It runs an on-device, multilingual AI model (SigLIP 2) in a separate, optional ml sidecar.
It's off by default and opt-in — the standard stack never starts it, so a normal deploy carries none of its weight, and it changes nothing for an existing install until you turn it on. On a low-power host you can simply leave it off: the All photos view still browses your whole library and filters by filename, gallery name, and IPTC keywords without the model.
Turn it on — start the extra container alongside your normal stack:
docker compose --profile ml up -d
Add to .env so the backend can reach it:
ML_SERVICE_URL=http://ml:8001
Then enable it under Settings → Content search (with an accuracy slider and live index progress). If the sidecar isn't running, that page detects it and explains how to start it, instead of offering a toggle that can't work.
Good to know:
- CPU-only — no GPU required. The model (~a few hundred MB, INT8) downloads once on first use into
./data/ml-cache. That directory is a regenerable cache, so it does not need backing up. - Resources. Indexing runs in the background on a small, bounded worker pool so it yields to serving. Tune
ML_THREADSandML_QUANTIZEDin.env(see the table above); lowerML_THREADSon a busy box. Your existing photos are indexed once when you enable it; new uploads index automatically. - Image. The sidecar ships as
ghcr.io/nielsfranke/contactsheet-ml;--profile mlpulls (or builds) it. It mounts your photos read-only.
Back to the Home index.