Skip to main content

How to Self-Host n8n with Docker Compose (2026 Guide)

· 4 min read

n8n is a popular open-source automation tool – like Zapier, but self-hosted. Here's how to run it on your own VPS using Docker Compose, and expose it securely over HTTPS using Caddy as the ingress proxy.

If you want a broader primer, check out How to Self-Host a Docker Compose App. But you don't need to read it first – this guide is self-contained.

🗓️ Last updated: May 2026. Tested with the latest n8nio/n8n image on Ubuntu 24.04.


1. Install Docker on your VPS

Update the system and install Docker + Compose plugin:

apt update && apt upgrade -y
apt-get install ca-certificates curl -y
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc

echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" \
| tee /etc/apt/sources.list.d/docker.list > /dev/null

apt-get update
apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y

2. Write a Docker Compose file

Create a new directory for n8n and add docker-compose.yml:

services:
n8n:
image: n8nio/n8n:latest
restart: always
ports:
- "127.0.0.1:5678:5678"
environment:
- N8N_HOST=n8n.example.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
volumes:
- n8n_data:/home/node/.n8n

volumes:
n8n_data:

💡 Note: This guide assumes you already have a domain (like n8n.example.com) pointing to your VPS's IP address. If not, set that up with your DNS provider before continuing.

Notice we bind to 127.0.0.1:5678 – so it's only accessible locally. Caddy will handle public access.

Start it:

docker compose up -d

Optional: Use PostgreSQL instead of SQLite

By default n8n stores everything in a SQLite file inside the volume. That's fine for personal use. For anything with real workflow volume, switch to PostgreSQL – it handles concurrent writes far better and is easier to back up.

Add a Postgres service and point n8n at it:

services:
n8n:
image: n8nio/n8n:latest
restart: always
ports:
- "127.0.0.1:5678:5678"
environment:
- N8N_HOST=n8n.example.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=n8n
- DB_POSTGRESDB_PASSWORD=change-me
volumes:
- n8n_data:/home/node/.n8n
depends_on:
- postgres

postgres:
image: postgres:16
restart: always
environment:
- POSTGRES_DB=n8n
- POSTGRES_USER=n8n
- POSTGRES_PASSWORD=change-me
volumes:
- n8n_pg:/var/lib/postgresql/data

volumes:
n8n_data:
n8n_pg:

💡 Set a real password and keep the n8n_pg volume – that's where your workflows and credentials now live. Back it up with docker compose exec postgres pg_dump -U n8n n8n > backup.sql.


3. Make it survive reboots

Create a systemd service:

# /etc/systemd/system/n8n.service
[Unit]
Description=n8n workflow automation (Docker Compose)
After=network.target

[Service]
Type=oneshot
WorkingDirectory=/root/n8n
ExecStart=/usr/bin/docker compose up -d
ExecStop=/usr/bin/docker compose down
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Enable it:

systemctl enable n8n
systemctl start n8n

Now n8n restarts automatically after reboots.


4. Install and configure Caddy

Caddy is a modern reverse proxy with automatic HTTPS. Perfect for small setups.

If you're curious about how Caddy compares to Nginx, HAProxy, or Traefik, see The Reverse Proxy Showdown. For n8n, Caddy is the simplest choice.

Make sure your domain (e.g. n8n.example.com) already resolves to your VPS before you configure Caddy. Otherwise, Let's Encrypt won't be able to issue a certificate.

apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | tee /etc/apt/trusted.gpg.d/caddy-stable.asc
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
apt update
apt install caddy -y

Edit the Caddyfile:

nano /etc/caddy/Caddyfile

Add:

n8n.example.com {
reverse_proxy localhost:5678
}

Reload Caddy:

systemctl reload caddy

That's it – Caddy requests and renews Let's Encrypt certificates automatically.


5. Secure access

  • Use strong credentials when creating first user.
  • Keep the docker-compose.yml volume so your workflows persist.
  • Optionally, restrict access to your IP range using Caddy if it's just for personal use.

Wrapping Up

You now have a self-hosted n8n instance:

  • Running in Docker Compose
  • Restarting automatically after reboots
  • Exposed via Caddy with HTTPS

If you want to avoid managing servers altogether, platforms like Hostim.dev let you paste a Compose file and get HTTPS, metrics, and persistence without touching SSH – on a flat monthly price, not metered per-minute billing.

But if you prefer DIY – this setup will take you far.