How to Self-Host n8n with Docker Compose on Ubuntu 24.04
Description and use
Deploy n8n on an Ubuntu 24.04 VPS using Docker Compose, PostgreSQL, Caddy, and an external task runner for HTTPS and secure credential storage.
Problem
Deploy a secure, production‑ready n8n instance on a VPS with HTTPS, PostgreSQL, and an external task runner.
Outcome
n8n is now running securely behind Caddy with HTTPS, using PostgreSQL for persistence and an external task runner for code execution, all managed via Docker Compose.
Workflow
- Open firewall for SSH, 80, 443
- Create project directory and .env with secrets
- Add init-data.sh to create non‑root PostgreSQL user
- Write compose.yaml defining postgres, n8n, and runners services
- Run docker compose up -d
- Verify Caddy obtains TLS certificate and routes to n8n
- Confirm n8n accessible via https://YOUR_DOMAIN
- Update by editing .env and re‑deploying
Evidence
This n8n Docker Compose stack runs n8n 2.41.6, its n8nio/runners task runner and PostgreSQL 18, with Caddy in front for HTTPS on ports 80 and 443.
Publish n8n on 127.0.0.1:5678 only. Docker-published ports bypass UFW, so a public 5678 stays open even when UFW denies it.
Set N8N_ENCRYPTION_KEY, N8N_WEBHOOK_URL and N8N_PROXY_HOPS=1.
n8n's sizing example lists 320 MB to 2 GB of memory for n8n itself. The optional n8n Assistant sandbox needs 4 GB RAM and 2 vCPU.
- Record date: 2026-10-15T14:56:03.891Z