How to Deploy n8n for Workflow Automation with Docker Compose
Connect your CRM to your helpdesk to your email marketing. Here is how to deploy n8n with persistent data and automatic backups.
n8n connects your applications so they talk to each other without manual intervention. New lead in your CRM creates a task in your project management tool. Completed task generates an invoice. Paid invoice updates the CRM. Here is how to deploy n8n on your server.
Step 1: Create the Docker Compose File
services:
n8n-db:
image: postgres:16-alpine
container_name: n8n-db
restart: unless-stopped
volumes:
- ./db:/var/lib/postgresql/data
environment:
POSTGRES_USER: n8n
POSTGRES_PASSWORD: n8n_password
POSTGRES_DB: n8n
n8n:
image: n8nio/n8n:latest
container_name: n8n
restart: unless-stopped
ports:
- "127.0.0.1:5678:5678"
volumes:
- ./n8n_data:/home/node/.n8n
environment:
N8N_HOST: automation.yourdomain.com
N8N_PORT: 5678
N8N_PROTOCOL: https
NODE_ENV: production
WEBHOOK_URL: https://automation.yourdomain.com
DB_TYPE: postgresdb
DB_POSTGRESDB_HOST: n8n-db
DB_POSTGRESDB_PORT: 5432
DB_POSTGRESDB_DATABASE: n8n
DB_POSTGRESDB_USER: n8n
DB_POSTGRESDB_PASSWORD: n8n_password
EXTERNAL_FRONTEND_HOOKS_URL: https://automation.yourdomain.com
N8N_EDITOR_BASE_URL: https://automation.yourdomain.com
N8N_ENCRYPTION_KEY: your_32_char_encryption_key
depends_on:
- n8n-dbStep 2: Configure the Reverse Proxy
Add a proxy host for automation.yourdomain.com pointing to n8n:5678. Request an SSL certificate. Force SSL. The webhook URL must be HTTPS for external services to send data to your workflows.
Step 3: Create Your First Workflow
Open https://automation.yourdomain.com. Create the admin account. Start with a simple workflow that demonstrates the pattern:
- Add a Webhook trigger node. This receives data from external services.
- Add an HTTP Request node to call your CRM API and create a new lead.
- Add an IF node to check whether the lead's source is Website or Referral.
- For website leads, add a Mattermost node to post a notification in the Sales channel.
Each n8n node is a drag-and-drop block. The webhook URL is generated automatically when you activate the workflow. External services POST data to this URL, and n8n runs the workflow.
Step 4: Connect Your Applications
n8n has built-in nodes for dozens of applications. For your self-hosted stack:
- PostgreSQL node: Query any database in your stack directly
- HTTP Request node: Connect to any REST API
- Webhook node: Receive data from any service that can send HTTP requests
- Email node: Send emails through your SMTP server
- Mattermost, Nextcloud, and ERPNext nodes: Built-in support
For applications without native nodes, the HTTP Request node works with any REST API. Add authentication headers and JSON body payloads directly in the node configuration.
Step 5: Back Up Your Workflows
n8n stores workflows in PostgreSQL. Back up the database and the n8n_data directory. This preserves your workflows, credentials, and execution history:
# Backup script
pg_dump -h localhost -U n8n n8n > n8n-backup-$(date +%Y-%m-%d).sql
tar -czf n8n-data-$(date +%Y-%m-%d).tar.gz ./n8n_dataSchedule this script with cron to run nightly. Store backups offsite.
If you would rather run your business than build automation workflows, VPS1 deploys n8n and connects your applications. Your CRM talks to your helpdesk. Your helpdesk talks to your invoicing. Everything works together. You stop doing manual data entry.
More articles
Cloudflare Tunnel vs. Tailscale vs. WireGuard: Bypassing CGNAT in Brunei
Three technologies let you bypass Brunei's residential CGNAT. Here is a detailed comparison of speed, privacy, cost, and complexity.
How to Access Your Home Network Remotely Under CGNAT in Brunei
CGNAT blocks direct remote access to your home network. Here are three methods to bypass it and securely reach your home devices from anywhere.
What Is CGNAT and Why It Affects Every Brunei Residential Internet User
Most Brunei home internet users are behind CGNAT and may not know it. Here is what CGNAT is, why ISPs use it, and how it limits what you can do online.