How to Self-Host n8n with Docker Compose (Step-by-Step, 2026)

A step-by-step guide to self-hosting n8n with Docker Compose and automatic HTTPS, using the exact commands and compose.yaml from n8n’s official docs. Plus Postgres, updates and backups.

How to Self-Host n8n with Docker Compose (Step-by-Step, 2026)

Short answer: install Docker, point a subdomain at your server, create a .env file and the official compose.yaml (n8n + Traefik for automatic HTTPS), then run docker compose up -d. The whole setup takes about 15–30 minutes. Every command and file below is taken from n8n’s official Docker Compose guide, so you can follow it line by line.

How do you self-host n8n with Docker Compose?

Self-host n8n with Docker Compose in eight steps: install Docker and Docker Compose, optionally allow your user to run Docker, add a DNS A record, create a .env file, create a local-files folder, paste n8n’s official compose.yaml, run docker compose up -d, and open your subdomain over HTTPS.

StepWhat you doTime
1Install Docker Engine and Docker Compose5–10 min
2(Optional) Let your user run Docker without sudo1 min
3Add a DNS A record for n8n.yourdomain.com2 min (+ DNS propagation)
4Create the .env file2 min
5Create the local-files folder1 min
6Create compose.yaml3 min
7Start with docker compose up -d1–2 min
8Open https://n8n.yourdomain.com and create the owner account2 min

What do you need before you start?

You need a Linux server with a public IP, a domain where you can add DNS records, and SSH access with sudo. For the server, 1–2 vCPUs and 2 GB of RAM are enough for most small setups; choose 4 GB if you plan to use AI agents or process files.

  • A server. Any Linux VPS works. See our VPS comparison for n8n for October 2026 prices, and our RAM sizing guide to choose the size.
  • A domain (or subdomain) you control, for example n8n.example.com.
  • Open ports 80 and 443 on the server firewall, so Traefik can get a certificate and serve HTTPS.
  • About 30 minutes.

Prefer a faster path? n8n also offers a one-line setup (curl -fsSL https://get.n8n.io | sh) that checks Docker, writes the configuration files and starts n8n for you. This guide uses the manual route so you know exactly what is running.

Step 1: Install Docker and Docker Compose

Install Docker Engine and the Docker Compose plugin using Docker’s official instructions for your Linux distribution, then confirm both are available. n8n’s guide links to Docker’s own pages rather than one script, because the steps differ between Ubuntu, Debian and other distributions.

Follow Install Docker Engine and Install the Compose plugin. Then check:

docker --version
docker compose version

Step 2: Optional – run Docker without sudo

To run Docker commands without typing sudo each time, add your user to the docker group and refresh your session. This step is optional. Note that membership of the docker group gives root-equivalent access to the host, so only add trusted users.

sudo usermod -aG docker ${USER}
exec sg docker newgrp

Check that your session sees the group:

groups

Step 3: Point a subdomain at your server

Create a DNS A record for the subdomain you want n8n on, for example n8n, pointing to your server’s public IP address. Traefik needs this record to resolve before it can request an HTTPS certificate from Let’s Encrypt.

Record typeNameDestination
An8n (or your chosen subdomain)your_server_IP_address

If your DNS is on Cloudflare, start with the record set to “DNS only” (grey cloud) so the certificate challenge reaches your server directly. You can test with dig n8n.example.com or any online DNS checker.

Step 4: Create the .env file

Create a project folder and, inside it, a .env file that sets your domain, subdomain, timezone and the email address used for the TLS certificate. Docker Compose reads these values into compose.yaml automatically.

mkdir n8n-compose
cd n8n-compose

Create .env with your own values:

DOMAIN_NAME=example.com
SUBDOMAIN=n8n
GENERIC_TIMEZONE=Europe/Berlin
[email protected]

With these values, n8n will be served at https://n8n.example.com. GENERIC_TIMEZONE is used by schedule-based nodes; n8n’s docs note that New York is the default if you don’t set it. Use a timezone name from the tz database, such as Asia/Dubai or America/New_York.

Step 5: Create the local-files folder

Inside the project folder, create a directory called local-files. n8n mounts it at /files so workflows can read and write files on the host, for example with the Read/Write Files from Disk node. Creating it yourself ensures the right ownership and permissions.

mkdir local-files

Step 6: Create compose.yaml

Create a compose.yaml file with two services: Traefik, which handles routing and free TLS certificates, and n8n, which listens only on localhost port 5678 behind Traefik. This is the file from n8n’s official guide, unchanged.

services:
  traefik:
    image: "traefik"
    restart: always
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.web.http.redirections.entryPoint.to=websecure"
      - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true"
      - "--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}"
      - "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - traefik_data:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock:ro

  n8n:
    image: n8nio/n8n
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    labels:
      - traefik.enable=true
      - traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`)
      - traefik.http.routers.n8n.tls=true
      - traefik.http.routers.n8n.entrypoints=web,websecure
      - traefik.http.routers.n8n.tls.certresolver=mytlschallenge
      - traefik.http.middlewares.n8n.headers.SSLRedirect=true
      - traefik.http.middlewares.n8n.headers.STSSeconds=315360000
      - traefik.http.middlewares.n8n.headers.browserXSSFilter=true
      - traefik.http.middlewares.n8n.headers.contentTypeNosniff=true
      - traefik.http.middlewares.n8n.headers.forceSTSHeader=true
      - traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME}
      - traefik.http.middlewares.n8n.headers.STSIncludeSubdomains=true
      - traefik.http.middlewares.n8n.headers.STSPreload=true
      - traefik.http.routers.n8n.middlewares=n8n@docker
    environment:
      - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - N8N_WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - TZ=${GENERIC_TIMEZONE}
      - N8N_RESTRICT_FILE_ACCESS_TO=/files
    volumes:
      - n8n_data:/home/node/.n8n
      - ./local-files:/files

volumes:
  n8n_data:
  traefik_data:

What this file sets up, per n8n’s docs:

NameTypeMounted atPurpose
n8n_dataDocker volume/home/node/.n8nn8n’s SQLite database and encryption key
traefik_dataDocker volume/letsencryptTLS certificate data
./local-filesBind mount/filesFiles shared between n8n and the host

Two details worth knowing. First, N8N_WEBHOOK_URL is available from n8n 2.30.0; n8n’s docs say to use WEBHOOK_URL on earlier versions. Second, the image tag n8nio/n8n has no version, so it pulls the latest release. With n8n 3.0 arriving, you may prefer to pin a version (for example n8nio/n8n:2.x.y, using a real version number from the n8n releases page) and upgrade on purpose. See n8n 3.0 breaking changes.

Step 7: Start n8n

Start both containers in the background with docker compose up -d. Docker pulls the images, Traefik requests the certificate, and n8n starts. Use docker compose stop to stop the containers later, and docker compose logs to check what happened.

sudo docker compose up -d

To stop the containers:

sudo docker compose stop

If something looks wrong, check the logs (a standard Docker Compose command):

sudo docker compose logs -f n8n

Step 8: Open n8n and create your account

Open https://n8n.example.com (your subdomain and domain) in a browser. n8n is only reachable over HTTPS, not plain HTTP. On first visit, n8n asks you to create the owner account. Use a strong, unique password and store it in a password manager.

If you can’t reach the instance, n8n’s docs suggest checking two things: your server’s firewall settings and your DNS configuration. In practice, most first-run problems are a DNS record that hasn’t propagated yet or ports 80/443 closed at the cloud provider’s firewall.

How do you add Postgres instead of SQLite?

Add a postgres service and point n8n at it with DB_TYPE=postgresdb and the DB_POSTGRESDB_* variables. n8n recommends Postgres for production instances with more than a handful of users or workflows running around the clock. Existing SQLite data does not move over automatically.

n8n’s Install using Docker Compose page shows the Postgres pieces. Add the credentials to .env:

POSTGRES_USER=change-me-user
POSTGRES_PASSWORD=change-me-password
POSTGRES_DB=n8n

Add a postgres service under services: and a db-storage volume under volumes::

  postgres:
    image: postgres:18
    restart: always
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      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

Then add these lines to the n8n service’s environment list, and make n8n wait for the database:

      - 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}
    depends_on:
      postgres:
        condition: service_healthy

Keep the PGDATA line: n8n’s docs warn that Postgres 18 changed its default data location, and this line keeps the volume mount consistent. For a hardened example with a non-root database user, see the withPostgres example in n8n’s hosting repository.

How do you update n8n running in Docker Compose?

Update n8n by pulling the new image, stopping the old containers and starting again: docker compose pull, docker compose down, docker compose up -d. Your workflows and credentials survive because they live in the n8n_data volume. Always back up before a major version.

cd /path/to/n8n-compose
docker compose pull
docker compose down
docker compose up -d

Before upgrading to n8n 3.0, update to the latest 2.x first and clear Settings > Migration Report. n8n says moving to 3.x is one way. Our n8n 3.0 guide explains what breaks.

How do you back up a self-hosted n8n instance?

Back up the n8n_data volume (it contains the SQLite database and the encryption key), plus your .env and compose.yaml files. If you use Postgres, also dump the database regularly. Without the encryption key, n8n can’t decrypt your stored credentials.

Simple, reliable options:

  • Provider snapshots of the whole server, scheduled daily or weekly.
  • Database dumps with pg_dump if you use Postgres, copied off the server.
  • Workflow exports to Git or cloud storage as a second line of defence.

n8n’s hosting prerequisites also recommend nightly backups and warn that, in containers, data is lost if the volume isn’t persisted.

Security checklist for self-hosted n8n

Keep n8n behind HTTPS, expose only ports 80 and 443, use a strong owner password, keep the host and Docker updated, and back up the encryption key. The official compose file already binds n8n to 127.0.0.1:5678, so only Traefik is reachable from the internet.

  1. Firewall: allow SSH, 80 and 443 only.
  2. SSH: use key-based login and disable password login.
  3. Updates: patch the OS and update n8n on a schedule.
  4. Secrets: keep .env out of version control.
  5. Credentials: give each workflow the narrowest API permissions it needs.

How much does it cost to self-host n8n?

The n8n Community Edition is free; you pay for the server. A suitable VPS costs roughly €4–€25 a month depending on provider and size, as of October 2026. Compare that with Zapier, Make and n8n Cloud for your workload before you decide.

Our free n8n Cost & Hosting Planner estimates both the managed-plan cost and the server you’d need. For a worked comparison at 5k, 50k and 200k runs, read Zapier vs Make vs n8n: real cost.

Frequently asked questions

Is Docker Compose the official way to self-host n8n?

Yes. n8n’s documentation provides Docker Compose guides, and from n8n 3.0 self-hosted n8n requires a Docker-based deployment; npm and npx installs are no longer supported. Kubernetes and Helm setups are also supported.

Do I need a domain name to self-host n8n?

For the setup in this guide, yes. Traefik requests a free Let’s Encrypt certificate for a subdomain such as n8n.example.com, and n8n is only reachable over HTTPS. For local testing without a domain, n8n’s one-line setup or a plain Docker run on localhost is simpler.

Where does n8n store my data in Docker?

In this setup, the n8n_data Docker volume is mounted at /home/node/.n8n. It holds the SQLite database and n8n’s encryption key. Back up that volume; losing the encryption key means stored credentials can’t be decrypted.

How do I update n8n with Docker Compose?

In the folder with your compose file, run docker compose pull, then docker compose down, then docker compose up -d. Back up first, and read the release notes before major versions such as n8n 3.0, which is one-way.

Should I use SQLite or Postgres?

SQLite is fine for trying n8n and for small single-user setups. n8n recommends Postgres for production instances with more than a handful of users or workflows running around the clock.

Sources

n8n Docs: Docker Compose (cloud provider); n8n Docs: Install using Docker Compose; n8n Docs: One-line setup; Docker: Install Docker Engine. Commands checked against n8n’s documentation on 26 October 2026.

hamid7777 Avatar

Written & tested by

The Sophrai brief

One calm email when something actually matters.

New tools, real cost breakdowns and the automation news worth your time. No hype, no spam.