Skip to content

Free website migration on every plan ·Prices in $ USD

hello@hostlumi.com

Get started

n8n guide

n8n Docker Compose: Production Example with PostgreSQL and HTTPS (2026)

Short answer: to run n8n with Docker Compose in production, put three services in one compose.yaml: n8n, PostgreSQL for the database and a reverse proxy for HTTPS. Keep secrets in a .env file, set your own N8N_ENCRYPTION_KEY, persist /home/node/.n8n in a volume, and start everything with docker compose up -d. The full example is below.

This guide was written against the official n8n Docker documentation, checked on 19 November 2026, when the current stable n8n release was 2.48.5. n8n’s own guide uses Traefik as the proxy and the default SQLite database. Here we use PostgreSQL and Caddy, which is a common production setup with a shorter configuration.

What you need

Prefer not to manage a server? Our n8n VPS hosting comes with exactly this setup ready, plus backups and updates.

Quick start: the smallest n8n Docker Compose file

For testing on your own computer, including Docker Desktop on Windows or Mac, this is all you need:

services:
  n8n:
    image: n8nio/n8n:latest
    restart: unless-stopped
    ports:
      - "5678:5678"
    environment:
      - GENERIC_TIMEZONE=Asia/Dhaka
      - TZ=Asia/Dhaka
      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  n8n_data:

Run docker compose up -d and open http://localhost:5678. This uses SQLite, n8n’s default database, and has no HTTPS, so do not expose it to the internet like this.

Production n8n Docker Compose example (PostgreSQL + HTTPS)

Create a folder on your server, for example ~/n8n, and add three files: .env, compose.yaml and Caddyfile.

1. The .env file

# Your n8n address
N8N_DOMAIN=n8n.example.com
GENERIC_TIMEZONE=Asia/Dhaka

# PostgreSQL
POSTGRES_USER=n8n
POSTGRES_PASSWORD=change-this-long-random-password
POSTGRES_DB=n8n

# Encrypts the credentials n8n stores. Generate once, never change, back it up.
N8N_ENCRYPTION_KEY=paste-output-of-openssl-rand-hex-32

Generate the password and the encryption key with openssl rand -hex 32. Keep this file private: chmod 600 .env.

2. The compose.yaml file

services:
  postgres:
    image: postgres:16
    restart: unless-stopped
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
    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

  n8n:
    image: n8nio/n8n:2.48.5
    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}
      - N8N_HOST=${N8N_DOMAIN}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - N8N_WEBHOOK_URL=https://${N8N_DOMAIN}/
      - NODE_ENV=production
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - TZ=${GENERIC_TIMEZONE}
      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
    volumes:
      - n8n_data:/home/node/.n8n

  caddy:
    image: caddy:2
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    environment:
      - N8N_DOMAIN=${N8N_DOMAIN}
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
      - caddy_config:/config
    depends_on:
      - n8n

volumes:
  postgres_data:
  n8n_data:
  caddy_data:
  caddy_config:

3. The Caddyfile

{$N8N_DOMAIN} {
    reverse_proxy n8n:5678
}

Caddy requests and renews a free HTTPS certificate for your domain automatically. n8n itself publishes no ports: only Caddy is reachable from the internet, and it forwards traffic to n8n inside the Docker network.

4. Start n8n

docker compose up -d
docker compose logs -f n8n

When the log shows that the editor is accessible, open https://n8n.example.com and create the owner account.

What each part does

SettingWhy it matters
DB_TYPE=postgresdb and DB_POSTGRESDB_*Stores workflows, credentials and execution history in PostgreSQL instead of the default SQLite file, which holds up better as executions grow.
N8N_ENCRYPTION_KEYn8n encrypts saved credentials with this key. If you do not set one, n8n creates a random key in /home/node/.n8n. Setting it yourself means it lives in your .env and in your backups.
n8n_data:/home/node/.n8nKeeps n8n’s settings, encryption key and logs when the container is replaced. Keep this volume even when you use PostgreSQL.
N8N_HOST, N8N_PROTOCOLTell n8n its public address, so links in the editor are correct.
N8N_WEBHOOK_URLThe public URL used for webhook and form URLs. It is available from n8n 2.30.0; on older versions use WEBHOOK_URL instead.
GENERIC_TIMEZONE and TZSchedule Trigger and date nodes use this timezone. If you do not set it, n8n falls back to New York time.
Pinned image tagn8nio/n8n:2.48.5 instead of latest means n8n only changes version when you decide to update.

How to update n8n with Docker Compose

n8n recommends updating at least once a month. Read the release notes first, take a backup, then change the image tag in compose.yaml and run:

cd ~/n8n
docker compose pull
docker compose down
docker compose up -d

Database changes made by a newer version are not undone by switching the image tag back. If an update goes wrong, restore from your backup.

How to back up n8n running in Docker

You need two things: the database and the encryption key. Without the key, the credentials stored in the database cannot be decrypted.

# Database dump
docker compose exec -T postgres pg_dump -U n8n n8n > n8n-$(date +%F).sql

# Keep a copy of .env (it holds N8N_ENCRYPTION_KEY) somewhere safe, off the server

Copy the dump off the server every day, for example to object storage. A backup that lives only on the same server is lost with the server.

Common problems

When to add workers (queue mode)

A single n8n container handles a lot of work. When long workflows start to slow down the editor or webhooks, n8n can run in queue mode: Redis holds a queue of executions and separate worker containers process them. Every worker needs the same N8N_ENCRYPTION_KEY. Queue mode adds more moving parts, so start with the setup above and scale when you need to.

Run it yourself, or let us run it

Self-hosting n8n with Docker Compose is free and gives you unlimited executions. You also take on updates, backups, security and monitoring. If you would rather spend that time on workflows, HostLumi n8n hosting gives you your own n8n server with PostgreSQL, HTTPS, daily off-server backups and tested updates, from $19.00/mo a month. See also Is n8n free? and n8n pricing in 2026.

FAQ

Do I need Docker Compose to run n8n?

No, a single docker run command works for testing. Docker Compose is better for production because it keeps n8n, the database and the proxy in one file that you can version and restart together.

Should I use SQLite or PostgreSQL with n8n?

SQLite is the default and fine for testing. PostgreSQL is the better choice for production, especially as execution history grows or when you plan to use queue mode.

What is the official n8n Docker image?

n8n publishes its image as n8nio/n8n, also available as docker.n8n.io/n8nio/n8n.

How much RAM does n8n need in Docker?

A small instance runs on 2 GB of RAM including PostgreSQL. Workflows that process large files or many items at once need more.

Can I run n8n on Docker Desktop?

Yes. Use the quick start file above on Windows or Mac, then open http://localhost:5678. Do not expose a Docker Desktop instance to the internet.

How do I update n8n in Docker?

Back up, change the image tag, then run docker compose pull, docker compose down and docker compose up -d.

← All guides

Questions about hosting?

A person on our team replies in Bangla or English.