Skip to content
Wasevo
GuideAI & Automation 15 min read

n8n Docker Compose: a production setup you can maintain

An n8n Docker Compose reference: annotated queue-mode Compose file with Redis and workers, webhook processors, the licence caveat and an environment variable reference.

n8n Docker Compose: a production setup you can maintain

Summarize with:

Share:

An n8n Docker Compose setup is one Compose file that runs n8n with PostgreSQL, keeps its settings in an .env file and puts a reverse proxy with TLS in front. When one container is not enough, n8n's queue mode adds Redis and worker containers. This guide is the Compose reference. It was checked against n8n's documentation on 13 November 2026.

How to self-host n8n on a VPS already walks through the server, firewall, DNS, Caddy, Postgres, backups with a restore test and updates. This article does not repeat that. It covers a Compose file you can maintain, queue mode with workers, the licence question, and a reference for the environment variables you are most likely to set. The last section says what was run.

Key takeaways

  • n8n's Compose guide for cloud servers runs n8n and Traefik with SQLite, and n8n's production requirements page recommends PostgreSQL for production.
  • Queue mode needs PostgreSQL and Redis. n8n does not support SQLite in queue mode, and every process needs the same encryption key and the same version.
  • Redis holds the queue. If it loses queued jobs, n8n marks those executions as crashed instead of rebuilding them from PostgreSQL, so turn on Redis persistence.
  • n8n's pages disagree on whether queue mode is free, so confirm with n8n first.

What n8n's cloud-server Compose guide contains

n8n's Compose guide for cloud servers defines two containers, n8n and Traefik, with a .env file for the domain, subdomain, timezone and certificate email. It uses the untagged image n8nio/n8n, stores the SQLite database and encryption key in the n8n_data volume, and mounts a ./local-files directory at /files. It publishes n8n on 127.0.0.1:5678 and sets N8N_RESTRICT_FILE_ACCESS_TO=/files. Traefik handles ports 80 and 443, and n8n answers over HTTPS only.

The file leaves out PostgreSQL, backups, version pinning and queue mode. n8n's main Install using Docker Compose guide builds a different stack on SQLite and adds an optional step to switch to PostgreSQL. Neither guide covers queue mode.

How to keep a Compose file maintainable

Keep secrets and per-server values in .env, and keep structure in compose.yaml. Docker Compose substitutes ${VAR} from .env, and ${VAR:?message} stops with your message when the variable is empty, according to Docker's interpolation docs. Use that form for the database password, the encryption key and the runner token.

Three habits keep the file readable:

  1. Pin an exact n8n image tag in .env and use it for every n8n and runner image.
  2. Define shared settings once with a YAML anchor and merge them into each service, as Docker's fragments docs describe.
  3. Run docker compose config -q after every edit. It prints nothing when the file is valid.

The .env file for the queue-mode file below has these keys. Generate the three secrets with openssl rand -hex, as in the VPS guide.

KeyValue
N8N_VERSIONThe exact tag from the "Current stable" box on n8n's Compose page
N8N_HOSTNAMEn8n.example.com
GENERIC_TIMEZONEYour timezone, for example Europe/Stockholm
POSTGRES_USER, POSTGRES_DBn8n and n8n
POSTGRES_PASSWORD, RUNNERS_AUTH_TOKENRandom strings
N8N_ENCRYPTION_KEYA random string you also store in a password manager

When to move to n8n queue mode

Stay in regular mode until one n8n process becomes the limit. In regular mode one instance runs triggers, webhooks and executions. In queue mode, the main instance receives triggers and webhook calls, creates the execution and passes its ID to Redis. A worker takes the ID, reads the workflow from the database, runs it and writes the result back.

Regular modeQueue mode
Containersn8n, databaseMain, one or more workers, database, Redis
DatabaseSQLite or PostgreSQLPostgreSQL
Who runs workflowsThe main instanceWorkers
Add capacity byA bigger serverMore workers, optional webhook processors
Latency on webhooksDirectThe docs say the hand-off to a worker can add overhead and latency

n8n's docs publish no execution count at which to switch. Its performance page says to benchmark your own workflows. A concurrency limit in regular mode (Control concurrency) is a cheaper first step.

Two details from n8n's production requirements matter before you switch. Redis keeps queue state, and n8n does not rebuild lost jobs from PostgreSQL, so configure Redis persistence to match the work you can afford to lose. And in queue mode n8n stores binary data in the database by default, which grows PostgreSQL. External storage for binary data is not part of the Community edition.

n8n Docker Compose with queue mode: the full file

This file runs PostgreSQL, Redis with append-only persistence, the main instance, one worker, the worker's task runner and Caddy. It follows the withPostgresAndWorker example in n8n's n8n-hosting repository, uses the single-instance pieces from the VPS guide, and adds the anchors. The Caddyfile is the one from that guide.

yaml
name: n8n-queue

# Shared settings. Every n8n process (main, worker, webhook) reads this block.
x-n8n-env: &n8n-env
  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:?set POSTGRES_PASSWORD in .env}
  EXECUTIONS_MODE: queue
  QUEUE_BULL_REDIS_HOST: redis
  QUEUE_HEALTH_CHECK_ACTIVE: "true"
  N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY:?set N8N_ENCRYPTION_KEY in .env}
  GENERIC_TIMEZONE: ${GENERIC_TIMEZONE}
  TZ: ${GENERIC_TIMEZONE}
  N8N_RUNNERS_MODE: external
  N8N_RUNNERS_AUTH_TOKEN: ${RUNNERS_AUTH_TOKEN:?set RUNNERS_AUTH_TOKEN in .env}
  N8N_RUNNERS_BROKER_LISTEN_ADDRESS: 0.0.0.0

# Shared service settings: image, restart policy, data volume, start order.
x-n8n: &n8n
  image: docker.n8n.io/n8nio/n8n:${N8N_VERSION:?set N8N_VERSION in .env}
  restart: always
  volumes:
    - n8n_storage:/home/node/.n8n
  depends_on:
    postgres:
      condition: service_healthy
    redis:
      condition: service_healthy

services:
  postgres:
    image: postgres:18
    restart: always
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}
      POSTGRES_DB: ${POSTGRES_DB}
      PGDATA: /var/lib/postgresql/data
    volumes:
      - db_storage:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 5s
      timeout: 5s
      retries: 10

  redis:
    image: redis:7-alpine
    restart: always
    command: ["redis-server", "--appendonly", "yes"]
    volumes:
      - redis_storage:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 5s
      retries: 10

  # Main instance: editor, API, triggers and webhooks. It queues work and does not run it.
  n8n:
    <<: *n8n
    environment:
      <<: *n8n-env
      N8N_HOST: ${N8N_HOSTNAME}
      N8N_PROTOCOL: https
      N8N_EDITOR_BASE_URL: https://${N8N_HOSTNAME}/
      N8N_WEBHOOK_URL: https://${N8N_HOSTNAME}/
      N8N_PROXY_HOPS: "1"
      OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS: "true"

  # Worker: takes execution IDs from Redis and runs the workflows.
  n8n-worker:
    <<: *n8n
    command: worker --concurrency=5
    environment:
      <<: *n8n-env
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      n8n:
        condition: service_started

  # Task runner for the Code node, paired with the worker.
  n8n-worker-runner:
    image: n8nio/runners:${N8N_VERSION}
    restart: always
    environment:
      N8N_RUNNERS_AUTH_TOKEN: ${RUNNERS_AUTH_TOKEN}
      N8N_RUNNERS_TASK_BROKER_URI: http://n8n-worker:5679
    depends_on:
      - n8n-worker

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

volumes:
  db_storage:
  n8n_storage:
  redis_storage:
  caddy_data:
  caddy_config:

PGDATA is pinned because Postgres 18 changed its default data directory. Without it, an existing volume starts as an empty database. Do not raise the image tag on an existing volume without a dump and restore.

Notes on the blocks that differ from a single-instance file:

  • Same key everywhere. n8n's queue docs say the main instance's encryption key must be shared with every worker and webhook processor, or workers cannot read credentials. The x-n8n-env anchor guarantees it.
  • Worker start order. The worker starts after the main instance. On PostgreSQL, n8n 2.33.0 and later take a migration lock at startup, so the start order is a convenience and not the safeguard.
  • Worker concurrency. The worker runs 10 jobs at once by default. n8n recommends 5 or higher, because a low value with many workers can exhaust the database connection pool. The file sets 5.
  • Health checks. QUEUE_HEALTH_CHECK_ACTIVE makes each worker serve /healthz and /healthz/readiness on port 5678. The readiness endpoint reports whether the worker's database and Redis connections are ready.
  • Task runner placement. In the test run described below, the main instance logged no task broker while the worker logged one on port 5679. The file has only the worker's runner. n8n's example repository keeps both. n8n's task runner page says each worker needs its own runner, and the main instance needs one only when OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS is false, a setting it advises against in production. The test run matches that. A Code node running through the worker's runner was not tested.

Start it with docker compose up -d, then check each process:

bash
docker compose exec -T n8n wget -qO- http://localhost:5678/healthz/readiness
docker compose exec -T n8n-worker wget -qO- http://localhost:5678/healthz/readiness

Each should answer {"status":"ok"}. Only Caddy publishes ports, and n8n says to keep task broker port 5679 private.

Add more workers

Copy the n8n-worker and n8n-worker-runner blocks, rename both, and point the new runner's N8N_RUNNERS_TASK_BROKER_URI at the new worker's name. n8n's task runner page says each worker needs its own runner, so copy the pair. Every worker needs Redis and database access.

Add webhook processors

A webhook processor receives production webhook requests so the main instance stays free for the editor. It is optional. n8n's docs start one with the webhook command and the same EXECUTIONS_MODE. Add this service to the file. It inherits the Postgres and Redis dependencies from the &n8n block:

yaml
  n8n-webhook:
    <<: *n8n
    command: webhook
    environment:
      <<: *n8n-env
      N8N_WEBHOOK_URL: https://${N8N_HOSTNAME}/
      N8N_PROXY_HOPS: "1"

Route webhook paths to it at the proxy. n8n's docs list /webhook/* and /webhook-waiting/* for the processor pool and say everything else, including /webhook-test/*, goes to the main instance. They advise against putting the main instance in the webhook pool. A Caddyfile for that split:

code
{$N8N_HOSTNAME} {
	@hooks path /webhook/* /webhook-waiting/*
	handle @hooks {
		reverse_proxy n8n-webhook:5678
	}
	handle {
		reverse_proxy n8n:5678 {
			flush_interval -1
		}
	}
}

To stop the main instance from handling production webhooks at all, set N8N_DISABLE_PRODUCTION_MAIN_PROCESS=true on it.

Queue mode and the licence

n8n's edition comparison says the Community edition includes queue mode and excludes multi-main mode. Its pricing page lists "Queue mode for scaling" under the Business plan. Both were checked on 13 November 2026, and they do not agree. Is n8n free? explains the licence and the wider conflict, and n8n pricing explained covers plan prices.

Some queue-related features are paid either way. The queue docs mark multi-main setup and the workers view in Settings as Enterprise on self-hosted n8n. If you run n8n for clients, n8n's license FAQ tells you to contact [email protected] about managing multiple client environments. Ask about queue mode in the same email and keep the reply.

Updating an n8n Docker Compose stack in queue mode

The update steps in the VPS guide apply. Queue mode adds one rule. n8n's update guide says to run the same version on every main process, worker and webhook processor, to pin a tag instead of latest, and to keep the n8nio/runners version equal to the n8nio/n8n version. Update them all as one change. With the file above, one N8N_VERSION edit in .env does that. n8n's Docker guide has the Compose update commands, but it carries an outdated notice, and n8n's update guide still links to it for Docker Compose updates.

Before you update, note the newest migration: SELECT name FROM migrations ORDER BY id DESC LIMIT 1;. You need it to know where to stop if you revert. Changing the tag back does not undo database migrations. To roll back, stop every process, then either revert migrations with n8n db:revert or restore the backup, as the update guide describes.

n8n environment variable reference

These tables list the variables used above and the ones people most often set, with defaults from n8n's environment variable pages, checked on 13 November 2026. Certain variables accept a _FILE suffix that reads the value from a file.

Instance and URLs

VariableDefaultWhat it does
N8N_ENCRYPTION_KEYRandom, generated on first launchEncrypts stored credentials. Share it with every worker.
N8N_HOSTlocalhostHost name n8n runs on.
N8N_EDITOR_BASE_URLnonePublic URL of the editor, also used in emails.
N8N_WEBHOOK_URLnoneBase URL for webhooks behind a proxy. From n8n 2.30.0. WEBHOOK_URL is its deprecated alias from 2.35.0.
N8N_PROXY_HOPS0Number of reverse proxies in front of n8n.
GENERIC_TIMEZONEAmerica/New_YorkInstance timezone for schedule nodes.

Database

VariableDefaultWhat it does
DB_TYPEsqlitesqlite or postgresdb.
DB_POSTGRESDB_HOSTlocalhostPostgreSQL host.
DB_POSTGRESDB_DATABASEn8nDatabase name.
DB_POSTGRESDB_USERpostgresDatabase user.
DB_POSTGRESDB_PASSWORDnoneDatabase password.

n8n supports PostgreSQL 17 and 18 as of July 2026, plus 16 for compatibility, according to its database page.

Queue mode and Redis

VariableDefaultWhat it does
EXECUTIONS_MODEregularSet to queue on the main instance, workers and webhook processors.
QUEUE_BULL_REDIS_HOSTlocalhostRedis host.
QUEUE_BULL_REDIS_PASSWORDnoneRedis password.
QUEUE_HEALTH_CHECK_ACTIVEfalseTurns on worker health endpoints.
QUEUE_HEALTH_CHECK_PORT5678Port for those endpoints.
OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERSfalseRuns manual executions on workers.
N8N_CONCURRENCY_PRODUCTION_LIMIT-1Production execution limit. In queue mode it overrides the worker's --concurrency flag when set.
N8N_WEBHOOK_RESPONSE_RELAY_SIZE_MAX64Largest worker response in MiB. Redis needs about 1.5 times this per response in flight.
N8N_DISABLE_PRODUCTION_MAIN_PROCESSfalseStops the main instance serving production webhooks.
N8N_MULTI_MAIN_SETUP_ENABLEDfalseMulti-main mode. Needs a licence.

Executions and data

VariableDefaultWhat it does
EXECUTIONS_DATA_PRUNEtrueDeletes old execution data on a rolling basis.
EXECUTIONS_DATA_MAX_AGE336Age in hours before deletion.
N8N_DEFAULT_BINARY_DATA_MODEdefaultdefault keeps binary data in memory. Other modes are filesystem, database, s3 and azure. In queue mode the default is database (docs).

Task runners, security and logs

VariableDefaultWhat it does
N8N_RUNNERS_MODEinternalexternal runs runners as separate containers. The docs mark internal deprecated.
N8N_RUNNERS_AUTH_TOKENRandomShared secret between n8n and its runners. Required in external mode.
N8N_RUNNERS_BROKER_LISTEN_ADDRESS127.0.0.1Address the task broker listens on. Set 0.0.0.0 for containers.
N8N_RUNNERS_TASK_BROKER_URIhttp://127.0.0.1:5679Set on the runner to reach the broker.

If it still does not work

  • The worker starts and no job runs. Check that EXECUTIONS_MODE=queue, the Redis host and the encryption key match on every process. n8n says the key must be shared.
  • Runner logs say the task broker is not ready. Wait for the n8n log to say it is ready, then check the runner log again. If the warning never stops, compare the runner's N8N_RUNNERS_TASK_BROKER_URI and auth token with n8n's task runner page, and check that the process it points at runs a task broker.

What was run and what was not

The documentation supplied the commands and variables. On 13 November 2026, on a Mac with Docker Compose, docker compose config -q accepted the Compose file above and stopped with a named error when .env was absent. The file was then started with the n8n image tag from n8n's example .env, which was not the current stable tag that day, plus PostgreSQL 18 and Redis 7, without Caddy, and under a throwaway project name with no published ports. The main instance logged no task broker and the worker logged one on port 5679. The main instance and the worker each answered {"status":"ok"} on /healthz/readiness, the worker registered its JavaScript and Python runners, and Redis reported appendonly yes. The same file with an added n8n-webhook service started, and its readiness endpoint answered. Both Caddyfiles passed caddy validate in the caddy:2 image. The containers and volumes were then removed.

Not run: Caddy serving a certificate, a real DNS name, a workflow execution on a worker, a Code node through the runner, backups, restores, updates, rollback commands and the licence behaviour. Those follow the linked documentation. Test them on a spare server first.

Next step

If you want n8n installed on a server you own, with backups and updates handled for you, see n8n automation services, which covers self-hosted installation and backups. Wasevo lists n8n and Docker among its platforms. Hosting and server management covers the server side.

Frequently asked questions

Not for a small test, because n8n defaults to SQLite. n8n recommends PostgreSQL for production, and its production requirements say it does not support SQLite in queue mode. Choosing PostgreSQL from the first day avoids moving data between databases later.

Sami Ullah

Written by

Sami Ullah

Full-stack Developer at Wasevo. Writes about web and app builds, hosting, migrations, WHMCS and keeping servers healthy.

Related guides

Get new guides by email

One short email when we publish something useful. No spam; unsubscribe at any time.

n8n · AI agents · Integrations

Automate the work your team repeats.

Book a free call

15 minutes, no sales pitch