This page covers Docker deployment and production best practices. See also: n8n Overview, Item Flow, AI Agents.
n8n Self-Hosting
Deployment Options
| Option | Cost | Best For |
|---|---|---|
| n8n Cloud | From $24/mo | Quick start, no infrastructure management |
| Self-hosted (VPS) | ~$5-20/mo | Full control, cost-effective at scale |
| Docker | Free (your hardware) | Local development, enterprise deployment |
Self-hosted gives you unlimited workflows, no execution limits, and full data ownership.
Cloud vs. Self-Hosted Comparison
| Feature | n8n Cloud | n8n Self-Hosted |
|---|---|---|
| Setup time | Minutes | 1-4 hours |
| Monthly cost | $20-$50+ | $6-$15 (VPS) |
| Execution limits | Yes (by tier) | Unlimited |
| Data privacy | Third-party servers | Your infrastructure |
| SSL/HTTPS | Included | You configure |
| Backups | Managed | Your responsibility |
| Updates | Automatic | Manual (Docker pull) |
Docker Deployment Guide
Prerequisites
- Server or VPS running Ubuntu 20.04+ (22.04 recommended)
- Docker and Docker Compose installed
- Port 5678 open for access
- Optionally: a domain name for HTTPS
1
Install Docker
sudo apt update && sudo apt install docker.io docker-compose -y
sudo systemctl enable docker --now
docker -v && docker-compose -v
2
Create working directory
mkdir ~/n8n && cd ~/n8n
3
Create docker-compose.yml (basic)
version: '3'
services:
n8n:
image: n8nio/n8n
container_name: n8n
ports:
- "5678:5678"
environment:
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=your-strong-password-here
- N8N_HOST=your-domain.com
- N8N_PORT=5678
- WEBHOOK_URL=https://your-domain.com/
volumes:
- n8n-data:/home/node/.n8n
restart: unless-stopped
volumes:
n8n-data:
4
Start n8n
docker-compose up -d
# Access: http://localhost:5678 or http://your.server.ip:5678
5
Add HTTPS (required for production)
sudo apt install nginx certbot python3-certbot-nginx -y
Create NGINX config at /etc/nginx/sites-available/n8n:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:5678;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
Enable and secure:
sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d your-domain.com
6
Upgrade to PostgreSQL for production
Replace docker-compose.yml with production config:
version: '3'
services:
postgres:
image: postgres:15
environment:
POSTGRES_USER: n8n
POSTGRES_PASSWORD: your-db-password
POSTGRES_DB: n8n
volumes:
- postgres-data:/var/lib/postgresql/data
restart: unless-stopped
n8n:
image: n8nio/n8n
container_name: n8n
ports:
- "5678:5678"
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=n8n
- DB_POSTGRESDB_PASSWORD=your-db-password
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=admin
- N8N_BASIC_AUTH_PASSWORD=your-strong-password
- WEBHOOK_URL=https://your-domain.com/
volumes:
- n8n-data:/home/node/.n8n
depends_on:
- postgres
restart: unless-stopped
volumes:
n8n-data:
postgres-data:
Adding a Local AI Model
Keep the entire pipeline on your infrastructure using Ollama:
# Install Ollama on your server
curl -fsSL https://ollama.com/install.sh | sh
# Pull and run models
ollama pull llama3
ollama pull mistral
# Models accessible at http://localhost:11434
# Configure n8n's Ollama node to point to this endpoint
This creates a fully private AI automation pipeline: workflows in n8n on your server, AI inference in Ollama on the same server. No data leaves your infrastructure.
Production Checklist
- HTTPS enabled via NGINX + Certbot (or Caddy)
- Strong admin password set
- PostgreSQL instead of SQLite for persistent storage
- Automated backups of Docker volumes
- Firewall (ufw: allow only 22, 80, 443)
- Fail2ban installed to block brute-force attempts
- Monitoring (uptime check, disk space alert)
- Update schedule (check n8n releases monthly)
VPS Cost Reference
| Provider | Spec | Monthly Cost | Suitable For |
|---|---|---|---|
| Hetzner CX22 | 2 vCPU, 4GB RAM | ~$5/mo | n8n alone |
| DigitalOcean Basic | 2 vCPU, 4GB RAM | ~$12/mo | n8n + small DB |
| DigitalOcean | 2 vCPU, 8GB RAM | ~$24/mo | n8n + medium workloads |
| Hetzner CX52 | 8 vCPU, 32GB RAM | ~$38/mo | n8n + Ollama model |
When to Choose Cloud vs. Self-Hosted
| Situation | Recommended |
|---|---|
| Prototyping / testing quickly | Cloud |
| Processing customer PII | Self-hosted |
| Less than 500 workflow runs/day | Cloud |
| More than 1,000 consistent runs/day | Self-hosted |
| No internal DevOps capacity | Cloud |
| Long-term cost optimization | Self-hosted |
| Data residency requirements | Self-hosted |