This guide covers operational practices for running incus-templated in production environments.
compose.yaml StackCreate a .env file alongside compose.yaml to provide the trust token (no --os-env needed):
echo "INCUS_TOKEN=$(incus config trust add --quiet incus-templated)" > .env
Here is the recommended production stack deploying Caddy alongside incus-templated:
services:
caddy:
image: docker.io/library/caddy:2.11.4-alpine
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- config:/config
- data:/data
command: |
sh -c 'if [ ! -f /config/Caddyfile ]; then echo -e "{\n\tadmin localhost:2019\n}\n:80 {\n\trespond \"Caddy initializing...\" 503\n}\n" > /config/Caddyfile; fi; exec caddy run --config /config/Caddyfile --adapter caddyfile'
healthcheck:
# 127.0.0.1, not localhost: Caddy's admin listens on IPv4 and localhost may resolve to ::1.
test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1:2019/config/"]
interval: 5s
retries: 12
incus-templated:
image: ghcr.io/lxc/incus-templated/incus-templated:1.0.0-beta.2
restart: unless-stopped
depends_on:
caddy:
condition: service_healthy
ports:
- "9153:9153"
environment:
INCUS_TEMPLATED_INCUS: "${INCUS_TEMPLATED_INCUS:-https://10.0.1.1:8443}"
INCUS_TEMPLATED_DATA_DIR: /var/lib/incus-templated
INCUS_TEMPLATED_TARGETS: "edge,preset=caddy,instance=caddy-1,project=default"
INCUS_TEMPLATED_HTTP_ADDRESS: ":9153"
INCUS_TEMPLATED_LOG: "INFO"
secrets:
- token
volumes:
- incus-templated:/var/lib/incus-templated
secrets:
token:
environment: INCUS_TOKEN
volumes:
config:
data:
incus-templated:
config:/config:
Persistent Incus custom storage volume holding /config/Caddyfile. incus-templated connects directly to this volume over SFTP to write and update the configuration.data:/data:
Persistent volume where Caddy stores automatic TLS certificates (from Let's Encrypt / ZeroSSL) and OCSP stapling cache.incus-templated:/var/lib/incus-templated:
Stores incus-templated's enrolled client TLS certificate (client.crt, client.key) so trust tokens are only needed once.Because /config is backed by a custom storage volume:
incus-compose restart caddy) or the Incus host reboots, Caddy immediately starts up using the persisted Caddyfile on the volume.incus-templated to initialize.If Caddy is temporarily stopped (e.g. during maintenance or image upgrades):
incus-templated detects the container is stopped./config and writes the updated Caddyfile directly to the volume via SFTP.incus-templated reloads it, so it does not keep serving the previous file.By default, incus-templated monitors all visible Incus projects. You can restrict monitoring to specific projects:
incus-templated run \
--project prod \
--project staging \
--target edge,preset=caddy,instance=caddy,project=default
You can route different services to different Caddy instances using separate label prefixes (via repeated flags or comma-separated):
# Repeated flags
incus-templated run \
--target public,preset=caddy,instance=caddy-external,project=default \
--target internal,preset=caddy,instance=caddy-internal,project=default
# Or comma-separated
incus-templated run \
--target "public,preset=caddy,instance=caddy-external,project=default,internal,preset=caddy,instance=caddy-internal,project=default"
user.label.public route to caddy-external.user.label.internal route to caddy-internal.Inspect the active configuration directly inside the Caddy container:
incus-compose exec caddy cat /config/Caddyfile
Increase log verbosity using INCUS_TEMPLATED_LOG=DEBUG or TRACE:
incus-compose logs -f incus-templated
DEBUG logs display:
instance-started, instance-stopped, instance-renamed).caddy fmt exit codes and output.If you suspect a configuration syntax issue:
incus-compose exec caddy caddy fmt /config/Caddyfile
opening SFTP session for volume ... not found:
Verify that Caddy's /config directory is backed by a named storage volume in compose.yaml.["caddy" "reload" ...] failed with connection refused in its output:
Caddy's admin API is not reachable. Verify that Caddy is running and that its global block includes { admin localhost:2019 }; with admin off, Caddy cannot be reloaded. The file is already in place, but the deploy counts as failed: it is retried with backoff, and every later event tries again until a reload succeeds. For a host target whose service may be down, use a reload that tolerates it, such as reload: [systemctl, try-reload-or-restart, caddy], or no-reload.readiness 503 Service Unavailable:
Indicates the chain is still performing the initial fleet sweep or is disconnected from the Incus API. Check network connectivity to Incus.