SysAdmin Tools

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.

1. Deployment Type
2. Basic Config
3. Database (PostgreSQL)
4. n8n Settings
5. Reverse Proxy
6. Additional Services
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. 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. 2

    Set the basics

    Enter your domain, pick the n8n version and timezone. The webhook URL is derived from your domain automatically.

  3. 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. 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. 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

A production n8n deployment is a small stack of containers defined in 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.
FieldDescription
n8n serviceThe main application container, listening internally on port 5678.
postgres serviceThe recommended database for durable storage of workflows and executions.
N8N_ENCRYPTION_KEYEncrypts stored credentials; must never change after first run or credentials become unreadable.
WEBHOOK_URL / N8N_HOSTPublic HTTPS URL settings so webhook callbacks reach the instance correctly.
.env fileHolds passwords, keys and tunables that Compose injects into the services.
reverse proxyNginx or Traefik terminates HTTPS and forwards to n8n on 5678.
volumesNamed Docker volumes that persist n8n data and the database across restarts.
Redis / Ollama / QdrantOptional 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?
n8n is an open-source, fair-code workflow automation tool — a self-hostable alternative to services like Zapier and Make. You connect apps and APIs into automated workflows using a visual editor. To self-host, you run it with Docker (usually via Docker Compose) on a VPS or server, back it with PostgreSQL, and put a reverse proxy in front for HTTPS. This generator produces the docker-compose.yml, .env and nginx.conf to do exactly that.
How to install n8n with Docker Compose?
Create a directory (e.g. ~/n8n), place the generated docker-compose.yml and .env files in it, then run docker compose up -d. Compose pulls the images, creates the volumes, and starts n8n along with PostgreSQL and any extra services. Check progress with docker compose logs -f n8n, then visit your domain to complete the owner-account setup.
What database should I use for n8n?
PostgreSQL is recommended for any serious use. n8n defaults to SQLite, which is fine for quick testing but struggles with concurrency and large execution histories. PostgreSQL handles concurrent executions, scales better, and is easier to back up. This generator defaults to a PostgreSQL deployment and wires the connection environment variables for you.
How to set up n8n with PostgreSQL?
Run a postgres container alongside n8n and set the database environment variables: DB_TYPE=postgresdb, DB_POSTGRESDB_HOST=postgres, DB_POSTGRESDB_DATABASE, DB_POSTGRESDB_USER and DB_POSTGRESDB_PASSWORD. Give PostgreSQL a named volume so data persists. The generated docker-compose.yml includes a postgres service, a healthcheck, and these variables already configured from your .env values.
How to add SSL to self-hosted n8n?
Put a reverse proxy in front of n8n to terminate TLS. With Nginx, use the generated nginx.conf to proxy your domain to n8n on port 5678 and obtain a certificate with Certbot/Let's Encrypt. With Traefik, labels handle certificates automatically. Then set N8N_PROTOCOL=https, N8N_HOST and WEBHOOK_URL to your https domain so webhooks and the editor use the secure URL.
How to connect n8n with Ollama for AI?
Add an Ollama service to the Compose stack (this generator can include it, with optional GPU support) and reference it from n8n's AI/LangChain nodes using the internal URL http://ollama:11434. Pull a model with docker compose exec ollama ollama pull llama3. Because Ollama runs locally, your prompts and data never leave the server — useful for private or sensitive automations.
What are the system requirements for n8n?
A small n8n + PostgreSQL stack runs comfortably on a VPS with 1–2 vCPUs and 2 GB of RAM for light use. Heavier workflows, queue mode with Redis, or adding Ollama (which needs several GB of RAM, more with larger models) increase requirements significantly — Ollama with mid-size models typically wants 8 GB+ and benefits from a GPU. Always give Docker volumes enough disk for execution history and the database.
How to backup n8n Docker deployment?
Back up two things: the PostgreSQL database and the n8n data volume. Dump the database with docker compose exec postgres pg_dump -U <user> <db> > backup.sql, and archive the named volumes (or your bind-mounted data directory). Also securely store your .env — especially N8N_ENCRYPTION_KEY, because without the exact key your encrypted credentials cannot be restored. Schedule these backups regularly.
How to update self-hosted n8n?
Pin or update the image tag in docker-compose.yml (e.g. from a fixed version to a newer one), then run docker compose pull followed by docker compose up -d to recreate the containers with the new image. Back up your database and volumes first. Review the n8n release notes for breaking changes, and never change N8N_ENCRYPTION_KEY during an upgrade.
How to set up n8n webhooks with nginx?
Webhooks need n8n to know its public URL. Set N8N_HOST to your domain, N8N_PROTOCOL=https, N8N_PORT=5678, and WEBHOOK_URL=https://your-domain/. In nginx.conf, proxy_pass to http://127.0.0.1:5678 and forward the Host and X-Forwarded-* headers (plus Upgrade/Connection for the editor's websocket). With those set, externally triggered workflows receive callbacks at https://your-domain/webhook/... correctly.
Why must I keep the n8n encryption key safe?
n8n encrypts all stored credentials (API keys, passwords used in workflows) with N8N_ENCRYPTION_KEY. If you lose or change this key, every saved credential becomes undecryptable and you must re-enter them. Generate it once, store it in your .env and a secure password manager or secrets store, include it in backups, and never rotate it casually. This generator creates a strong random key for you.

Related Tools