n8n Docker Compose Generator
Generate a docker-compose.yml for self-hosted n8n with PostgreSQL, Nginx + SSL, and optional Ollama, Redis or Qdrant.
Advertisement
Test Before Applying
Generated configuration is a starting point. Always:
- Test in a non-production environment
- Validate syntax before reloading services
- Keep a backup of your working config
- Adapt to your specific server setup
SysAdmin Tools provides this as a reference only and is not responsible for service interruptions.
services:
n8n:
image: n8nio/n8n:latest
restart: unless-stopped
ports:
- "5678:5678"
environment:
- N8N_HOST=${N8N_HOST}
- N8N_PORT=5678
- N8N_PROTOCOL=https
- WEBHOOK_URL=${WEBHOOK_URL}
- GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
- TZ=${GENERIC_TIMEZONE}
- N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY}
- EXECUTIONS_TIMEOUT=${EXECUTIONS_TIMEOUT}
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
- DB_POSTGRESDB_USER=${POSTGRES_USER}
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- n8n_data:/home/node/.n8n
depends_on:
- postgres
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 5
volumes:
n8n_data:
postgres_data:Advertisement
Advertisement
This n8n Docker Compose generator builds a complete docker-compose.yml for self-hosting n8n, the open-source workflow-automation tool. Choose PostgreSQL or SQLite, add a reverse proxy with SSL, and optionally bolt on Ollama, Redis or Qdrant — then copy a ready-to-run stack plus its .env file.
Running n8n self-hosted properly means more than a single container: you want a real database, a reverse proxy terminating HTTPS, a stable encryption key, and the right environment variables for webhooks. This n8n docker compose generator wires all of that together — a n8n docker compose postgresql setup with nginx ssl, generated secrets, and optional AI services — so you can go from zero to a working instance on a VPS in minutes.
Everything is generated in your browser, including random passwords and the 32-character encryption key. Copy the docker-compose.yml, .env and nginx.conf tabs, follow the setup commands, and run docker compose up -d.
How to Use the n8n Docker Compose Generator
- 1
Pick a deployment type
Choose n8n with PostgreSQL (recommended for production), SQLite (simplest), or a bundle with Ollama AI or Qdrant for AI workflows.
- 2
Set the basics
Enter your domain, pick the n8n version and timezone. The webhook URL is derived from your domain automatically.
- 3
Generate secrets
Click Generate for the database password and the encryption key. The encryption key is critical — n8n uses it to encrypt stored credentials, so keep it safe and never change it after first run.
- 4
Choose a reverse proxy and extras
Select Nginx (with optional Let's Encrypt), Traefik, or none. Toggle Ollama, Redis (for queue mode) or Qdrant as needed.
- 5
Copy the files and deploy
Copy the docker-compose.yml, .env and (if selected) nginx.conf tabs into a directory on your server, then run the setup commands ending in docker compose up -d.
Understanding the n8n Docker Compose Setup
docker-compose.yml. The core n8n service runs the application; a postgres service gives it durable storage (strongly preferred over SQLite once you have more than a handful of workflows); and a reverse proxy such as Nginx or Traefik terminates TLS and forwards traffic to n8n's internal port 5678. Secrets and tunables live in a separate .env file that Compose reads automatically.
Two environment variables matter most. N8N_ENCRYPTION_KEY is used to encrypt stored credentials — it must stay constant for the life of the instance, because changing it makes existing credentials unreadable. The webhook settings (N8N_HOST, WEBHOOK_URL, N8N_PROTOCOL) must reflect your public HTTPS domain so that externally triggered workflows receive callbacks at the correct URL. Getting these wrong is the most common cause of broken webhooks in self-hosted n8n.
Optional services extend the stack. Redis enables queue mode, letting n8n scale executions across worker processes. Ollama runs local LLMs for AI nodes without sending data to third parties. Qdrant provides a vector database for retrieval-augmented AI workflows. Each is added as another service with its own volume so data persists across restarts.| Field | Description |
|---|---|
| n8n service | The main application container, listening internally on port 5678. |
| postgres service | The recommended database for durable storage of workflows and executions. |
| N8N_ENCRYPTION_KEY | Encrypts stored credentials; must never change after first run or credentials become unreadable. |
| WEBHOOK_URL / N8N_HOST | Public HTTPS URL settings so webhook callbacks reach the instance correctly. |
| .env file | Holds passwords, keys and tunables that Compose injects into the services. |
| reverse proxy | Nginx or Traefik terminates HTTPS and forwards to n8n on 5678. |
| volumes | Named Docker volumes that persist n8n data and the database across restarts. |
| Redis / Ollama / Qdrant | Optional services for queue mode, local LLMs and vector search respectively. |
Advertisement
Common n8n Self-Hosting Use Cases
Production n8n with PostgreSQL + Nginx SSL
The recommended baseline: n8n backed by PostgreSQL, fronted by Nginx with a Let's Encrypt certificate, and a fixed encryption key — a durable setup for real automation workloads.
Private AI workflows with Ollama
Add an Ollama service so n8n's AI nodes call local models, keeping prompts and data on your own server instead of a third-party API.
Scale with queue mode and Redis
Enable Redis to run n8n in queue mode, distributing workflow executions across worker containers for higher throughput.
RAG pipelines with Qdrant
Include a Qdrant vector database alongside n8n to build retrieval-augmented generation workflows that search embeddings.
n8n Docker Compose — Frequently Asked Questions
What is n8n and how to self-host it?
How to install n8n with Docker Compose?
What database should I use for n8n?
How to set up n8n with PostgreSQL?
How to add SSL to self-hosted n8n?
How to connect n8n with Ollama for AI?
What are the system requirements for n8n?
How to backup n8n Docker deployment?
How to update self-hosted n8n?
How to set up n8n webhooks with nginx?
Why must I keep the n8n encryption key safe?
Related Tools
Nginx Config Generator
Fine-tune the Nginx reverse proxy that fronts your n8n instance.
HestiaCP Template Generator
Serve n8n behind HestiaCP with a reverse-proxy web template.
Password Generator
Generate extra strong secrets for your database and basic auth.
SSL Checker
Confirm the certificate on your n8n domain is valid after setup.