This page covers Docker deployment and production best practices. See also: n8n Overview, Item Flow, AI Agents.

n8n Self-Hosting

Deployment Options

OptionCostBest For
n8n CloudFrom $24/moQuick start, no infrastructure management
Self-hosted (VPS)~$5-20/moFull control, cost-effective at scale
DockerFree (your hardware)Local development, enterprise deployment

Self-hosted gives you unlimited workflows, no execution limits, and full data ownership.

Cloud vs. Self-Hosted Comparison

Featuren8n Cloudn8n Self-Hosted
Setup timeMinutes1-4 hours
Monthly cost$20-$50+$6-$15 (VPS)
Execution limitsYes (by tier)Unlimited
Data privacyThird-party serversYour infrastructure
SSL/HTTPSIncludedYou configure
BackupsManagedYour responsibility
UpdatesAutomaticManual (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

ProviderSpecMonthly CostSuitable For
Hetzner CX222 vCPU, 4GB RAM~$5/mon8n alone
DigitalOcean Basic2 vCPU, 4GB RAM~$12/mon8n + small DB
DigitalOcean2 vCPU, 8GB RAM~$24/mon8n + medium workloads
Hetzner CX528 vCPU, 32GB RAM~$38/mon8n + Ollama model

When to Choose Cloud vs. Self-Hosted

SituationRecommended
Prototyping / testing quicklyCloud
Processing customer PIISelf-hosted
Less than 500 workflow runs/dayCloud
More than 1,000 consistent runs/daySelf-hosted
No internal DevOps capacityCloud
Long-term cost optimizationSelf-hosted
Data residency requirementsSelf-hosted