Skip to content

Docker Compose recipes

Ready-to-run Compose setups for an always-on PiFi server, one per way of reaching it. Each recipe is a directory in deploy/compose/ with a compose.yaml, a commented .env.example and the proxy’s own configuration. Copy the directory to the server, fill in .env, and run docker compose up -d.

Recipe Reached at Certificates Open ports Pick it when
Caddy a public name Let’s Encrypt, automatic 80, 443 You have a domain and a machine reachable from the internet
Traefik a public name Let’s Encrypt, automatic 80, 443 You already run Traefik, or want label-based routing
nginx any name yours (certbot, DNS challenge, private CA) 80, 443 Certificates come from somewhere else
Tailscale https://<name>.<tailnet>.ts.net Tailscale, automatic none Only your own devices should reach it
Cloudflare Tunnel a public name on Cloudflare Cloudflare, automatic none You want a public name without opening ports
Host agent n/a n/a none A machine that runs Pi is itself managed with Compose

To try PiFi on one machine, skip all of this and run pifi up (getting-started.md).

Phones, browsers and terminals reach an entry point (Caddy, Traefik, nginx, Tailscale serve or a Cloudflare Tunnel) over HTTPS. The entry point forwards to the coordinator container on port 7400 over the Compose network. Host agents on your machines dial out to the same public URL; the coordinator never dials them.

What every recipe does

  • The coordinator publishes no port. Only the entry point in the same Compose project reaches it, so it trusts X-Forwarded-For from Docker’s private ranges (PIFI_TRUSTED_PROXIES) and rate limits count real clients.
  • State lives in the data volume: coordinator.db, admin.token and catalog-secrets/. Back it up with docker compose exec pifi pifi coordinator backup /data/backup-$(date +%F).db and copy the file out (operations.md).
  • Single sign-on is required. Off localhost the coordinator refuses to start without an OpenID Connect provider and an owner. Set the PIFI_OIDC_* lines in .env and register <public URL>/api/auth/oidc/callback as the redirect URI at the provider (auth.md). Any OpenID Connect provider works; provider notes cover Authelia, Authentik, Keycloak and Pocket ID.
  • Nothing sits in front of PiFi’s own sign-in. No basic auth, forward auth or Cloudflare Access: host agents, webhooks and installed apps cannot pass one.
  • The image is pinned to the release these files ship with. To upgrade, change the tag (or pull the new deploy/compose/ files) and docker compose up -d; see operations.md.
  • Pi never runs here. The coordinator only stores state and relays; it needs neither a home directory nor the Docker socket, and no recipe gives it either.

After docker compose up -d, open the public URL, sign in with single sign-on, and add a host from Settings › Hosts › Add host (or set PIFI_HOST_ENROLL_SECRET and let hosts enroll themselves, below).

Caddy

deploy/compose/caddy/: Caddy gets and renews a Let’s Encrypt certificate for PIFI_DOMAIN and forwards WebSockets on its own.

Terminal window
cd caddy
cp .env.example .env # PIFI_DOMAIN, PIFI_OIDC_*
docker compose up -d
docker compose logs -f caddy # watch the certificate arrive

The name must resolve to the machine, and ports 80 and 443 must be reachable from the internet for the ACME challenge. On a private network, use a DNS challenge instead (a Caddy build with your DNS provider’s module) or the Tailscale recipe.

Traefik

deploy/compose/traefik/: Traefik with the Docker provider, an HTTP-to-HTTPS redirect and a Let’s Encrypt resolver using the TLS-ALPN challenge. PiFi is routed by labels on its service.

Terminal window
cd traefik
cp .env.example .env # PIFI_DOMAIN, ACME_EMAIL, PIFI_OIDC_*
docker compose up -d

Already running Traefik? Drop the traefik service, attach pifi to Traefik’s network (networks: [proxy] with proxy declared external: true), and keep its labels, changing the entrypoint and resolver names to yours. For the file provider, use deploy/traefik.example.yaml. Either way, add no buffering, compression, retry or login middleware to the router.

nginx

deploy/compose/nginx/: nginx with a certificate you provide in certs/ (fullchain.pem, privkey.pem). The template sets up the WebSocket upgrade, turns off response buffering, keeps sockets open for an hour and accepts 32 MB attachments.

Terminal window
cd nginx
cp .env.example .env # PIFI_DOMAIN, PIFI_OIDC_*
mkdir certs && cp /etc/letsencrypt/live/pifi.example.com/{fullchain,privkey}.pem certs/
docker compose up -d

Reload nginx after renewing the certificate (docker compose exec nginx nginx -s reload). A certificate from a private CA works only on devices that trust that CA; passkeys, push and the installed app need it trusted.

Tailscale

deploy/compose/tailscale/: a Tailscale container joins your tailnet and tailscale serve gives the coordinator an HTTPS name with a real certificate. The coordinator shares the Tailscale container’s network, so it is reachable only from the tailnet and the machine opens no port at all.

Terminal window
cd tailscale
cp .env.example .env # TS_AUTHKEY, TS_HOSTNAME, TS_TAILNET, PIFI_OIDC_*
docker compose up -d

Before the first start, turn on MagicDNS and HTTPS certificates in the tailnet’s DNS settings. Use a tagged, reusable auth key so the node does not expire; its state stays in the tailscale-state volume. Phones and host agents must be on the tailnet too. Passkeys, push notifications and the installed app all work with the ts.net name. Single sign-on still applies: the OIDC provider must be reachable from your devices, and its redirect URI is https://<TS_HOSTNAME>.<TS_TAILNET>/api/auth/oidc/callback.

Cloudflare Tunnel

deploy/compose/cloudflare-tunnel/: cloudflared holds an outbound tunnel to Cloudflare, which serves PIFI_DOMAIN with its own certificate. No port is opened on the machine.

  1. In Cloudflare Zero Trust › Networks › Tunnels, create a tunnel and copy its token.

  2. Add a public hostname: PIFI_DOMAIN, service http://pifi:7400.

  3. Fill in .env and start it:

    Terminal window
    cd cloudflare-tunnel
    cp .env.example .env # PIFI_DOMAIN, CLOUDFLARE_TUNNEL_TOKEN, PIFI_OIDC_*
    docker compose up -d

Do not add a Cloudflare Access application on the hostname: host agents and the installed app cannot pass it. WebSockets must stay enabled for the zone (the default). Host agents reconnect by themselves if Cloudflare drops an idle socket; they ping every 20 seconds, so it rarely happens.

Host agent in a container

deploy/compose/host/ runs a host agent, the part that runs Pi, in a container built from the PiFi image plus Pi. Prefer the native service (pifi host install-service, deployment.md); use this only when the machine with the repositories is itself managed with Compose.

Terminal window
cd host
cp .env.example .env # PIFI_COORDINATOR_URL, PIFI_HOST_ENROLL_SECRET, HOST_HOME, HOST_UID, HOST_GID
docker compose up -d --build
  • The home directory is mounted at the same path inside the container, and the container runs as that home’s owner. The coordinator records worktree paths, and Pi’s credentials, sessions, host.json and the host state all live in that home.
  • Pi runs with that user’s full privileges: it can read and write everything the home holds. Mount the least you need and never the Docker socket (privilege model).
  • PI_VERSION must be in the supported range (compatibility.md).
  • With PIFI_HOST_ENROLL_SECRET set (on the coordinator too), the host enrolls itself on first start. Without it, run docker compose run --rm pifi-host host enroll --coordinator <url> --token <token> once with a token from Settings › Hosts › Add host.

Connecting hosts

Hosts connect outbound to the public URL, so any recipe works for hosts behind NAT. On each machine that should run Pi:

Terminal window
npm install -g @spencerboucher/pifi
pifi host enroll --coordinator https://pifi.example.com --token <token>
pifi host install-service

or, with a shared secret, set PIFI_COORDINATOR_URL and PIFI_HOST_ENROLL_SECRET in the service environment and skip enroll. Details: deployment.md and auth.md.

Troubleshooting

Symptom Likely cause
pifi exits at start with a single sign-on error PIFI_OIDC_ISSUER, PIFI_OIDC_CLIENT_ID or every PIFI_OIDC_OWNER_* is empty in .env
The proxy starts but returns 502 The coordinator is still starting or exited: docker compose ps, docker compose logs pifi
Sign-in fails with a redirect mismatch The provider’s redirect URI is not exactly <public URL>/api/auth/oidc/callback
The web app loads but stays “Reconnecting” Something between the browser and the coordinator blocks WebSocket upgrades or buffers responses
Passkeys, push or Add to Home Screen do not work The certificate is not trusted by the device, or the URL is not HTTPS with a domain name
Every client shares one rate limit PIFI_TRUSTED_PROXIES does not cover the proxy’s address