Ask around for an n8n Docker Compose setup and you'll get five different answers, half of them missing HTTPS entirely, a couple with no persistent volume at all (great, until the container gets recreated and every workflow is gone), and none of them telling you how to update without crossing your fingers. None of that is because self-hosting n8n is hard. It's because most walkthroughs stop at docker compose up -d and call it done, when the real setup is three smaller problems stacked on top of each other: getting traffic to the container securely, making sure your data actually survives a restart, and updating later without finding out the hard way that you didn't.
This is part 3 of the site's self-hosting series. Part 1 covered moving an existing npm install to Docker before n8n 3.0 drops npm support; part 2 covered the storage-directory rename that comes with it. This post is for starting from zero: a from-scratch Compose setup with HTTPS, a volume that actually persists, and an update routine you can trust because you've tested it, not because it sounds plausible.
Blip: A docker-compose.yml with no named volume isn't a setup. It's a very elaborate way to lose data on a schedule.
Before you start
You'll need a server with Docker and the Compose plugin installed, a domain name with an A record pointed at that server's IP, and ports 80 and 443 open in whatever firewall sits in front of it. You don't need a specific VPS provider, any box that can run Docker and receive inbound traffic on those two ports works. If you'd rather skip owning the server entirely, a free n8n Cloud trial puts HTTPS, updates, and backups on n8n's own team instead of yours; the rest of this post is for when you want to run it yourself.
Step 1: Write the n8n Docker Compose setup
Two services: n8n itself, and Caddy in front of it handling HTTPS. Caddy gets the public ports; n8n stays off the public internet entirely and only talks to Caddy over the internal Docker network.
# docker-compose.yml
services:
n8n:
image: docker.io/n8nio/n8n:2.43.7 # pin to a specific tag, never :latest
restart: unless-stopped
environment:
- N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
- N8N_HOST=${N8N_HOST}
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://${N8N_HOST}/
- N8N_LISTEN_ADDRESS=0.0.0.0
expose:
- "5678"
volumes:
- n8n_data:/home/node/.n8n
caddy:
image: caddy:2-alpine
restart: unless-stopped
environment:
- N8N_HOST=${N8N_HOST}
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
depends_on:
- n8n
volumes:
n8n_data:
caddy_data:
caddy_config:
Two things in there are worth calling out, because I only found them by actually running this, not by reading about it.
The N8N_LISTEN_ADDRESS=0.0.0.0 line isn't decoration. n8n's default listen address is ::, the IPv6 wildcard, and plenty of Docker hosts (this one included, when I first tested without that line) don't have IPv6 enabled on the default bridge network. Without it, n8n crashes on startup with n8n's address '::' is not available, and you're left debugging a networking problem that's actually a one-line environment variable. I hit this exact crash in testing and confirmed the fix starts it cleanly.
The environment: - N8N_HOST=${N8N_HOST} line under caddy, not just under n8n, is also not optional. A .env file next to a Compose file only gets used for variable substitution inside the Compose file itself; it isn't automatically injected into every container's runtime environment. Leave that line off the caddy service and the ${N8N_HOST} placeholder you're about to write into the Caddyfile resolves to nothing, Caddy's config fails to parse into a valid site block, and you get silence from the reverse proxy with nothing obviously wrong in docker compose ps. I reproduced this myself before adding that line: a working n8n container and a broken 502 from Caddy on every request, for exactly this reason.
Keep your real N8N_ENCRYPTION_KEY and N8N_HOST in a .env file next to the Compose file, not hardcoded:
N8N_ENCRYPTION_KEY=generate-this-once-and-never-change-it
N8N_HOST=n8n.yourdomain.com
Generate the key once with openssl rand -hex 32 the first time you ever run this, and never regenerate it afterward. Every credential n8n has ever encrypted is only decryptable with that exact key.
Step 2: Point Caddy at it for HTTPS
Caddy's whole pitch is that getting HTTPS right is its job, not yours. The Caddyfile is three lines:
# Caddyfile
{$N8N_HOST} {
reverse_proxy n8n:5678
}
With a real domain pointed at the server, Caddy requests and renews a Let's Encrypt certificate automatically on first start, no certbot, no cron job, no manual renewal, ever. That automatic-certificate behavior needs a real public domain and open ports 80/443 to work, which this sandbox doesn't have, so I couldn't test the live Let's Encrypt issuance end to end here. What I could test, and did, is the reverse proxy mechanics underneath it: I ran the same Caddyfile with tls internal added (Caddy's own local CA, used for exactly this kind of offline test) in front of a real running n8n container, and confirmed the whole chain works, TLS handshake, HTTP/2, and a 200 response from n8n's login page through the proxy. The only part Caddy swaps in production is where the certificate comes from; the proxying itself is the same code path either way, and that part is verified, not assumed.
Bring it up:
docker compose up -d
Give it a few seconds on first start (n8n runs its database migrations before it starts listening), then visit https://n8n.yourdomain.com. If you get a connection refused instead of a slow load, check the Caddy container's logs first; a malformed Caddyfile or a missing N8N_HOST on the caddy service (see Step 1) is the usual cause.
Step 3: Prove the data survives, don't assume it
A named volume is only "persistent" if you've actually checked that it is. I tore down and recreated the containers (not the volumes) and compared file checksums before and after:
docker compose exec n8n md5sum /home/node/.n8n/config /home/node/.n8n/database.sqlite
docker compose down
docker compose up -d
docker compose exec n8n md5sum /home/node/.n8n/config /home/node/.n8n/database.sqlite
Both checksums matched exactly, before and after. That's the actual guarantee docker compose down (without -v) is supposed to give you: it removes containers, not the named volumes they mounted. docker compose down -v removes volumes too, so don't reach for it out of habit when you just mean to restart.
Step 4: Back up, and prove the backup works by restoring it
A backup you've never restored is a guess. The backup itself is a one-liner against the named volume:
docker run --rm -v n8n_data:/data -v "$(pwd)":/backup alpine \
tar -czf /backup/n8n-backup-$(date +%Y%m%d).tar.gz -C /data .
I ran this against a live volume, then restored that exact archive into a brand-new, empty volume and compared checksums against the original:
docker volume create n8n_restore_test
docker run --rm -v n8n_restore_test:/data -v "$(pwd)":/backup alpine \
sh -c "tar -xzf /backup/n8n-backup-20261016.tar.gz -C /data && chown -R 1000:1000 /data"
Every file matched, byte for byte, which is the only version of "the backup works" worth trusting. A future post in this series covers backup strategy in more depth, including where the encryption key fits into a restore and how to automate this on a schedule; for now, know that the command above produces a restorable archive, because I restored it.
Step 5: Update without crossing your fingers
Updating is the same shape every time: back up, change the pinned tag, bring the one service up again.
# 1. Back up first (Step 4's command)
# 2. Edit docker-compose.yml: bump the n8n image tag to the version you've checked the changelog for
# 3. Pull and recreate only the n8n service
docker compose pull n8n
docker compose up -d n8n
Pinning to an exact tag, rather than :latest, means an update only happens when you change that one line, not whenever Docker happens to re-pull the image. If something breaks after an update, you have the backup from step 2 and the previous tag still sitting in your Compose file's git history to roll back to. Check the n8n release notes for breaking changes before bumping more than one minor version at a time, especially around the 3.0 line this series has been tracking.
Where to start
Run Steps 1 through 4 on a throwaway VPS before you ever point real workflows at this. Confirm HTTPS loads, confirm the checksum test in Step 3 actually matches, and confirm you can restore your own backup, not just create one. Once all three of those are true, you have a setup worth trusting with production credentials, not just one that happened to boot.
If you outgrow this single-container shape later, high execution volume, multiple heavy workflows competing for CPU, n8n's queue mode splits the work across separate worker containers behind the same Postgres database. That's a real architecture change, not a Compose tweak, so treat it as a "when you actually need it" problem rather than something to build in from day one.
Disclosure: the n8n Cloud link above is an affiliate link, if you sign up through it, we may earn a commission at no extra cost to you. See our affiliate disclosure for details.
Top comments (0)