# n8n self-hosted: n8n + PostgreSQL + Caddy (automatic HTTPS) # Tested 2026-11-11 with n8n 2.47.3, postgres:18, caddy:2 (Docker 28.4, Docker Desktop on Windows 10). # Guide: mia-automation.com/en/guides/n8n-self-hosting-docker. Fill in .env first (see env.example). services: postgres: image: postgres:18 restart: unless-stopped environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: ${POSTGRES_DB} PGDATA: /var/lib/postgresql/data # keep: postgres 18 otherwise writes outside the volume volumes: - db-data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] interval: 5s timeout: 5s retries: 10 n8n: image: docker.n8n.io/n8nio/n8n:${N8N_VERSION} # pin a version; update on purpose, never "latest" restart: unless-stopped depends_on: postgres: condition: service_healthy environment: DB_TYPE: postgresdb DB_POSTGRESDB_HOST: postgres DB_POSTGRESDB_PORT: "5432" DB_POSTGRESDB_DATABASE: ${POSTGRES_DB} DB_POSTGRESDB_USER: ${POSTGRES_USER} DB_POSTGRESDB_PASSWORD: ${POSTGRES_PASSWORD} N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY} # without this key your saved credentials are lost N8N_HOST: ${N8N_DOMAIN} N8N_PROTOCOL: https N8N_PORT: "5678" N8N_WEBHOOK_URL: https://${N8N_DOMAIN}/ N8N_PROXY_HOPS: "1" GENERIC_TIMEZONE: ${TIMEZONE} TZ: ${TIMEZONE} N8N_DIAGNOSTICS_ENABLED: "false" EXECUTIONS_DATA_PRUNE: "true" EXECUTIONS_DATA_MAX_AGE: "336" # keep execution history for 14 days volumes: - n8n-data:/home/node/.n8n # no "ports": n8n is only reachable through Caddy caddy: image: caddy:2 restart: unless-stopped depends_on: - n8n command: caddy reverse-proxy --from ${N8N_DOMAIN} --to n8n:5678 ports: - "80:80" - "443:443" volumes: - caddy-data:/data - caddy-config:/config volumes: db-data: n8n-data: caddy-data: caddy-config: