n8n is a self-hosted workflow automation tool — connecting apps and APIs through a visual editor, similar to Zapier or Make, but running entirely on your own infrastructure.
Prerequisites
- Docker Engine and Docker Compose installed
- A domain name (recommended for production use with webhooks)
Step 1 — Create a Project Directory
mkdir ~/n8n && cd ~/n8n
Step 2 — Create docker-compose.yml
services:
n8n:
image: docker.n8n.io/n8nio/n8n
restart: unless-stopped
ports:
- "5678:5678"
environment:
- N8N_HOST=n8n.yourdomain.com
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://n8n.yourdomain.com/
- GENERIC_TIMEZONE=UTC
volumes:
- n8n_data:/home/node/.n8n
volumes:
n8n_data:
Step 3 — Start n8n
docker compose up -d
Step 4 — Add HTTPS via Nginx Proxy Manager
Route n8n.yourdomain.com to port 5678 — see How to Install Nginx Proxy Manager with Docker. HTTPS is important here since n8n handles webhook URLs and often credentials for connected services.
Step 5 — Access n8n
https://n8n.yourdomain.com
Create your owner account on first visit.
Creating Your First Workflow
- Click Add workflow
- Add a trigger node (schedule, webhook, or manual trigger)
- Add action nodes connecting to your desired services (email, Slack, database, HTTP requests)
- Test and activate the workflow
Using a Persistent Database (Recommended for Production)
By default n8n uses SQLite; for production workloads with many workflows, configure PostgreSQL instead:
services:
postgres:
image: postgres:16
restart: unless-stopped
environment:
POSTGRES_DB: n8n
POSTGRES_USER: n8n
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
n8n:
image: docker.n8n.io/n8nio/n8n
restart: unless-stopped
environment:
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_DATABASE=n8n
- DB_POSTGRESDB_USER=n8n
- DB_POSTGRESDB_PASSWORD=${DB_PASSWORD}
depends_on:
- postgres
volumes:
- n8n_data:/home/node/.n8n
volumes:
postgres_data:
n8n_data:
Backing Up n8n
docker exec n8n-postgres-1 pg_dump -U n8n n8n > n8n-db-backup.sql
docker run --rm -v n8n_n8n_data:/data -v $(pwd):/backup alpine tar czf /backup/n8n-data-backup.tar.gz /data
Common Errors
Webhooks don't trigger — confirm WEBHOOK_URL matches your actual public HTTPS domain exactly, including trailing slash conventions.
n8n loses workflows after container restart — confirm the volume is correctly configured and persisting data outside the container.
Best Practices
- Use PostgreSQL instead of default SQLite for any production workload with meaningful workflow volume
- Always run behind HTTPS given the sensitive nature of connected service credentials
- Back up both the database and the
.n8ndata volume regularly
Continue Reading
- How to Install Docker Compose on Ubuntu & Debian
- How to Install Nginx Proxy Manager with Docker
- How to Run MySQL, PostgreSQL & Redis in Docker Containers
Browse more articles in Popular Self-Hosted Applications.
