← Back to Gratin

Self-hosting · beta 0.1.0-beta.1

Run your own Gratin sync

Keep recipe sync and encrypted image storage on your own server. One Docker image bundles an Evolu sync relay and SeaweedFS for S3-compatible image storage, with one persistent volume and no Gratin account or subscription required.

What you need

A Linux AMD64 or ARM64 Docker host, Docker Compose v2 or newer, and a domain with a TLS reverse proxy. A VPS, home server or suitable NAS can run it. The beta is a single-server deployment for you and the people you trust; it does not provide public signups, per-user quotas or replication.

Install from the bundle

The bundle contains Compose and the full README. Compose is pinned to the released image digest, so an update cannot silently replace the image you installed. No registry login is needed.

Download and verify the bundle
(
set -eu
version=0.1.0-beta.1
base="https://updates.gratin.app/self-hosted/$version"
curl --fail --location --remote-name "$base/gratin-self-hosted-$version.tar.gz"
curl --fail --location --remote-name "$base/gratin-self-hosted-$version.tar.gz.sha256"
sha256sum --check "gratin-self-hosted-$version.tar.gz.sha256"
tar -xzf "gratin-self-hosted-$version.tar.gz"
)

On macOS, use shasum -a 256 -c instead of sha256sum --check. Open the extracted gratin-self-hosted-0.1.0-beta.1 folder, create .env using the template below, and fill in your two secrets. Then run docker compose -p gratin-sync up -d from that folder. Finish TLS setup below before connecting devices.

Docker Compose

For an existing deployment manager, copy this into compose.yaml and create .env alongside it. Keep the Compose project name gratin-sync stable across upgrades so Docker reuses the same volume.

Download compose.yaml

compose.yaml
services:
  relay:
    image: ghcr.io/rebsoftware/gratin-self-hosted@sha256:9acd3751171f8aa4cac88dfaee7a27e5a491beced3c0d05b9e47a138da52ce97
    init: true
    restart: unless-stopped
    stop_grace_period: 20s
    ports:
      - "127.0.0.1:4000:4000"
      - "127.0.0.1:9000:9000"
    environment:
      RELAY_TOKEN: ${RELAY_TOKEN:?Set RELAY_TOKEN in .env}
      S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:?Set S3_ACCESS_KEY_ID in .env}
      S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:?Set S3_SECRET_ACCESS_KEY in .env}
    volumes:
      - data:/data
volumes:
  data:

Use docker compose -p gratin-sync for the commands on this page. If your NAS or deployment manager supplies its own persistent project name, keep using that name instead. Port 9000 is optional administration access; you may omit its port mapping.

Environment variables

Create a file named .env next to compose.yaml using the template below. Write two different private secrets of at least 32 characters each: one for RELAY_TOKEN and another for S3_SECRET_ACCESS_KEY. Use long, unique passwords or passphrases; a password manager can generate them. Stick to letters, numbers and hyphens so the values work directly in both the file and your relay URL.

VariablePurposeRequirement
RELAY_TOKENShared admission token used by your Gratin clients.Required; at least 32 characters.
S3_ACCESS_KEY_IDAccess-key name for the bundled SeaweedFS object store.Required and nonempty; gratin-admin is suitable.
S3_SECRET_ACCESS_KEYSecret for the bundled SeaweedFS object store.Required; at least 32 characters, different from your relay token.
.env template — fill in both secrets
RELAY_TOKEN=
S3_ACCESS_KEY_ID=gratin-admin
S3_SECRET_ACCESS_KEY=

Do not start with the two blank secrets above. Restrict access to .env (chmod 600 .env) and keep it with your backups. Do not put the S3 credentials into Gratin's app settings.

Ports, storage and fixed settings

SeaweedFS runs in single-process mini mode inside the image; you do not need to install or manage a separate object store. You can change host-side port mappings and the Docker volume or bind mount. There are no configured record, object or owner storage quotas: monitor disk space, including temporary space for uploads. The 10,000,000-byte sync protocol message limit is separate from image storage.

Put TLS in front of port 4000

Point your domain at the server and configure your reverse proxy to forward both HTTP requests and WebSocket upgrades to port 4000. The supplied Compose file publishes ports on loopback only. Expose your proxy's HTTPS endpoint, not the S3 service or SeaweedFS's internal management ports.

For example, with Caddy running on the host, replace the domain below with your own:

Caddyfile example — proxy running on the host
sync.example.com {
    reverse_proxy 127.0.0.1:4000
}

If the proxy runs in another container, attach it to the same trusted Docker network and proxy to relay:4000 instead. Its own 127.0.0.1 refers to the proxy container, not Gratin's container.

Disable query-string logging on the proxy and any monitoring in front of it: client URLs contain your relay token. Use a valid TLS certificate and set request-size and timeout limits appropriate for your recipe photos.

Connect Gratin and your other devices

  1. In Gratin, open Settings → Sync → Advanced.
  2. Set Relay URL to wss://sync.example.com?token=YOUR_RELAY_TOKEN, using your own domain and relay token. Choose Save & reconnect.
  3. Under Sync devices, use the sync code or QR code from your existing library to connect another device to that same library. Set the same relay URL on each device.

A matching server URL alone does not join two independently created libraries. Export a backup before changing a device's sync identity, and keep your sync code or QR code private: it grants access to the library. Gratin derives both sync and image URLs from your relay URL.

For local desktop testing only, ws://localhost:4000?token=YOUR_RELAY_TOKEN works on the machine running Docker. On a phone, localhost means the phone itself; use your HTTPS-backed domain instead.

Check that it is running

Status and logs
docker compose -p gratin-sync up -d
docker compose -p gratin-sync ps
docker compose -p gratin-sync logs --tail=100 relay

GET /healthz on port 4000 checks object-store readiness as well as the HTTP service. Compose restarts an exited process; an unhealthy health check alone does not restart a running container. If startup fails, check all three environment variables, storage ownership and available disk space. For connection problems, check TLS, WebSocket forwarding and the relay token first.

Back up and restore

Stop the container with docker compose -p gratin-sync stop, back up the entire data volume and the original .env, then start it again with docker compose -p gratin-sync start. Copying live SQLite files is not a consistent backup. Restore both the complete volume and its matching .env while the container is stopped.

docker compose down retains the named volume. docker compose down -v deletes it. Keep device-side exports too; do not treat a beta sync server as your only backup.

Upgrade deliberately

Back up first, read the new release's instructions, then replace the image digest or Compose file while keeping .env, the data volume and the project name unchanged. Run docker compose -p gratin-sync pull followed by docker compose -p gratin-sync up -d. Do not assume an older image can read data changed by a newer one; keep your stopped-volume backup before upgrading.

License and help

The self-hosted backend and Evolu are MIT licensed; SeaweedFS is Apache-2.0 licensed. The licenses and third-party notices are included in the image and setup bundle. This does not change the Gratin app's license. For setup help, email [email protected] with your server type, image version and a redacted error. Never send your relay token, S3 secrets or sync code.