How to Self-Host n8n on Docker: A Step-by-Step Guide (2026)

How to self-host n8n on Docker - step-by-step guide

Updated October 2026 · Works with n8n 2.x

Docker is the easiest and most reliable way to install n8n. In this step-by-step guide you will run n8n in one command, then set up a proper Docker Compose installation with PostgreSQL and HTTPS that you can keep for years.

Quick answer: run docker run -it --rm -p 5678:5678 -v n8n_data:/home/node/.n8n n8nio/n8n and open http://localhost:5678. For a server that runs 24/7, use the Docker Compose setup in Method 2.

Which installation method should you use?

Method Best for Database
1. docker run Trying n8n on your computer SQLite
2. Docker Compose + PostgreSQL + HTTPS A server you will actually use PostgreSQL
3. Production with queue mode and workers High-volume, business-critical automation PostgreSQL + Redis

Method 3 is covered in detail in our complete n8n self-hosted guide. The npm/Node.js method still exists but is being phased out by n8n, so we recommend Docker.

Prerequisites

  • Docker installed (Docker Desktop on Windows/macOS, or Docker Engine on Linux).
  • For a server: a Linux VPS with at least 1 vCPU and 2 GB RAM, plus a domain or subdomain pointing to it.

Method 1: Try n8n with one Docker command

docker volume create n8n_data

docker run -it --rm 
  --name n8n 
  -p 5678:5678 
  -e GENERIC_TIMEZONE="Europe/Berlin" 
  -e TZ="Europe/Berlin" 
  -v n8n_data:/home/node/.n8n 
  n8nio/n8n

Open http://localhost:5678 and create your owner account. Your workflows are stored in the n8n_data volume, so they survive restarts.

This is perfect for learning, but not for production: it uses SQLite, has no HTTPS, and webhooks from the internet cannot reach your laptop.

Method 2: Install n8n with Docker Compose, PostgreSQL and HTTPS

Step 1: Install Docker on your server

curl -fsSL https://get.docker.com | sh
mkdir -p ~/n8n && cd ~/n8n

Step 2: Point your domain

Create an A record such as n8n.example.com pointing to your server’s IP address.

Step 3: Create the .env file

cat > .env <<EOF
N8N_VERSION=2.43.7
N8N_DOMAIN=n8n.example.com
POSTGRES_PASSWORD=$(openssl rand -hex 24)
N8N_ENCRYPTION_KEY=$(openssl rand -hex 32)
EOF
chmod 600 .env

Use the current stable version number for N8N_VERSION. Save a copy of N8N_ENCRYPTION_KEY somewhere safe. n8n encrypts all your credentials with it.

Step 4: Create docker-compose.yml

services:
  postgres:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: n8n
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: n8n
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U n8n -d n8n"]
      interval: 10s
      retries: 10

  n8n:
    image: n8nio/n8n:${N8N_VERSION}
    restart: unless-stopped
    environment:
      DB_TYPE: postgresdb
      DB_POSTGRESDB_HOST: postgres
      DB_POSTGRESDB_DATABASE: n8n
      DB_POSTGRESDB_USER: n8n
      DB_POSTGRESDB_PASSWORD: ${POSTGRES_PASSWORD}
      N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}
      N8N_HOST: ${N8N_DOMAIN}
      N8N_PROTOCOL: https
      N8N_WEBHOOK_URL: https://${N8N_DOMAIN}/   # n8n 2.30 and newer
      WEBHOOK_URL: https://${N8N_DOMAIN}/       # older versions
      N8N_PROXY_HOPS: "1"
      GENERIC_TIMEZONE: Europe/Berlin
      TZ: Europe/Berlin
      N8N_BLOCK_ENV_ACCESS_IN_NODE: "true"
    volumes:
      - n8n_data:/home/node/.n8n
    depends_on:
      postgres:
        condition: service_healthy

  caddy:
    image: caddy:2
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - caddy_data:/data
    depends_on:
      - n8n

volumes:
  postgres_data:
  n8n_data:
  caddy_data:

Step 5: Configure HTTPS with Caddy

cat > Caddyfile <<EOF
n8n.example.com {
    reverse_proxy n8n:5678
}
EOF

Replace n8n.example.com with your domain. Caddy gets a free SSL certificate from Let’s Encrypt automatically.

Step 6: 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, create the owner account and turn on two-factor authentication.

How to update n8n in Docker

cd ~/n8n
# back up first (see below), then set the new N8N_VERSION in .env
docker compose pull
docker compose up -d

Read the release notes before major updates, and never update without a fresh backup.

How to back up n8n in Docker

mkdir -p backups
docker compose exec -T postgres pg_dump -U n8n -Fc n8n > backups/n8n-$(date +%F).dump

Keep the database dump and your .env file (it contains the encryption key) in a safe, off-server location.

Troubleshooting

Problem Solution
Webhook URLs show http://localhost:5678 Set N8N_WEBHOOK_URL (n8n 2.30+) or WEBHOOK_URL to your HTTPS domain and restart.
“Permission denied” on /home/node/.n8n The volume must be writable by the node user (UID 1000). Use a named Docker volume as shown above.
SSL certificate not issued Check that DNS points to the server and ports 80/443 are open in your firewall.
Credentials stop working after reinstall You started n8n with a new encryption key. Restore the original N8N_ENCRYPTION_KEY.
Schedule triggers fire at the wrong hour Set GENERIC_TIMEZONE and TZ.
Code node errors about task runners Recent n8n versions run Code nodes in task runners. For production, add an n8nio/runners container with the same version, as shown in our self-hosted guide.

Next steps

FAQ

Is Docker required to run n8n?

No, but it is the recommended method. The npm installation is being phased out, and Docker makes updates, backups and moving servers much easier.

SQLite or PostgreSQL?

SQLite is fine for testing on your computer. Use PostgreSQL for any instance that runs real workflows.

How much RAM does n8n need in Docker?

2 GB is enough for a small personal instance. Teams with many active workflows should start with 4 GB.

Can I run n8n on Windows or Mac with Docker?

Yes. Install Docker Desktop and use Method 1. For an always-on instance that receives webhooks, use a Linux server.

Ready to Launch Your First Workflow?

Start your automation journey in under 60 seconds. No credit card required.

You May Also Like