M
MJK.Supplies
Home / n8n / n8n Docker Guide: Deploy and Scale with Containe…
n8n

n8n Docker Guide: Deploy and Scale with Containers

Running n8n with Docker is the recommended approach for production self-hosted deployments. Docker ensures consistent environments, easy updates, persistent data storage, and simple scaling. This guide covers everything from a basic Docker setup to a production-ready deployment with PostgreSQL, SSL, and monitoring.

M
MJK Supplies · May 21, 2026 · 12 min read
ShareXinf↗
n8n Docker Guide: Deploy and Scale with Containers

Why Docker for n8n

n8n can be installed via npm, but Docker is better for production because:

  • Isolation: n8n runs in its own container; no conflicts with other system software
  • Easy updates: docker pull n8nio/n8n:latest + restart = updated n8n
  • Persistence: Docker volumes keep your data safe across container restarts
  • Reproducibility: Same environment on any machine
  • Easy SSL: Use nginx reverse proxy container alongside n8n

Quick Start with Docker

The simplest Docker setup for development/testing:

docker run -it --rm \ --name n8n \ -p 5678:5678 \ -v ~/.n8n:/home/node/.n8n \ -e GENERIC_TIMEZONE="Europe/London" \ n8nio/n8n

Open http://localhost:5678. This uses SQLite by default and stores data in ~/.n8n.

Note: --rm removes the container when stopped. Remove it for persistent deployments.

Production Docker Compose Setup

For production, use Docker Compose with PostgreSQL:

version: '3.8' services: postgres: image: postgres:15 restart: unless-stopped environment: POSTGRES_DB: n8n POSTGRES_USER: n8n POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} volumes: - postgres_data:/var/lib/postgresql/data healthcheck: test: ['CMD-SHELL', 'pg_isready -U n8n'] interval: 5s timeout: 5s retries: 5 n8n: image: n8nio/n8n:latest restart: unless-stopped ports: - "5678:5678" environment: # Database - DB_TYPE=postgresdb - DB_POSTGRESDB_HOST=postgres - DB_POSTGRESDB_PORT=5432 - DB_POSTGRESDB_DATABASE=n8n - DB_POSTGRESDB_USER=n8n - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD} # n8n config - N8N_BASIC_AUTH_ACTIVE=true - N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER} - N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD} - N8N_HOST=${N8N_HOST} - N8N_PORT=5678 - N8N_PROTOCOL=https - WEBHOOK_URL=https://${N8N_HOST}/ - GENERIC_TIMEZONE=Europe/London - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY} # Email (optional, for workflow error notifications) - N8N_EMAIL_MODE=smtp - N8N_SMTP_HOST=${SMTP_HOST} - N8N_SMTP_PORT=587 - N8N_SMTP_USER=${SMTP_USER} - N8N_SMTP_PASS=${SMTP_PASS} volumes: - n8n_data:/home/node/.n8n depends_on: postgres: condition: service_healthy volumes: postgres_data: n8n_data:

Create .env file:

POSTGRES_PASSWORD=your-strong-password-here N8N_BASIC_AUTH_USER=admin N8N_BASIC_AUTH_PASSWORD=your-strong-password-here N8N_HOST=n8n.yourdomain.com N8N_ENCRYPTION_KEY=a-random-32-character-string-here SMTP_HOST=smtp.gmail.com SMTP_USER=your@email.com SMTP_PASS=your-app-password

Start:

docker compose up -d

Adding SSL with nginx

Add an nginx reverse proxy with Let's Encrypt:

# Add to docker-compose.yml services: nginx: image: nginx:alpine restart: unless-stopped ports: - "80:80" - "443:443" volumes: - ./nginx.conf:/etc/nginx/conf.d/default.conf - certbot_certs:/etc/letsencrypt depends_on: - n8n certbot: image: certbot/certbot volumes: - certbot_certs:/etc/letsencrypt command: certonly --webroot --webroot-path=/var/www/certbot -d n8n.yourdomain.com --email your@email.com --agree-tos
# nginx.conf server { listen 80; server_name n8n.yourdomain.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name n8n.yourdomain.com; ssl_certificate /etc/letsencrypt/live/n8n.yourdomain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/n8n.yourdomain.com/privkey.pem; location / { proxy_pass http://n8n:5678; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } }

Environment Variables Reference

Key n8n environment variables:

VariableDescriptionExample
N8N_BASIC_AUTH_ACTIVEEnable basic authtrue
N8N_HOSTDomain namen8n.example.com
N8N_ENCRYPTION_KEYEncrypt stored credentials32-char random string
DB_TYPEDatabase typepostgresdb or sqlite
WEBHOOK_URLExternal webhook base URLhttps://n8n.example.com/
EXECUTIONS_TIMEOUTMax workflow execution time3600 (seconds)
EXECUTIONS_DATA_MAX_AGEDelete execution data after (days)30
N8N_LOG_LEVELLogging verbosityinfo or debug

Updating n8n

docker compose pull n8n docker compose up -d n8n

n8n runs database migrations automatically on startup. Check the changelog before major version updates.

Backups

# Backup PostgreSQL database docker compose exec postgres pg_dump -U n8n n8n > backup-$(date +%Y%m%d).sql # Backup n8n data directory (credentials, settings) docker compose exec n8n tar czf - /home/node/.n8n > n8n-data-$(date +%Y%m%d).tar.gz

Set up automated daily backups via cron.

Recommended Tools

  • n8n — The automation platform
  • Docker — Container runtime
  • DigitalOcean — Simple VPS for n8n hosting ($20-40/month)
  • Hetzner — Affordable EU cloud for GDPR compliance
  • Cloudflare — DNS + DDoS protection for your n8n instance
#n8n#docker#devops#deployment

Related articles

MJK Supplies · Automation Services

Want this built for you?

We design and ship custom AI agents and automation systems for teams that want results, not a backlog. Book a free 30-minute consult — no commitment, no pitch deck.