How to Self-Host n8n with Docker Compose
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.
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
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.
But if you prefer DIY – this setup will take you far.