docker.recipes

n8n + PostgreSQL + Redis

intermediate

Workflow automation platform with 300+ integrations.

Overview

n8n (pronounced n-eight-n) is a fair-code workflow automation platform that serves as a powerful self-hosted alternative to services like Zapier and Microsoft Power Automate. Founded in 2019, n8n provides a visual workflow builder with over 350 pre-built integrations, allowing users to connect different services and automate complex business processes without writing code. Unlike SaaS alternatives, n8n's fair-code licensing model ensures the source code remains accessible while providing enterprise features for commercial use. This production-ready stack combines n8n with PostgreSQL for robust data persistence and Redis for high-performance queue management. PostgreSQL stores workflow definitions, execution history, and user credentials with ACID compliance, while Redis handles the execution queue system that enables horizontal scaling through worker processes. The configuration includes a separate n8n-worker container that processes workflows asynchronously, preventing the main application from becoming overwhelmed during high-volume automation runs. This stack is ideal for organizations requiring scalable workflow automation with enterprise-grade reliability. Small to medium businesses benefit from the cost savings compared to per-execution SaaS pricing, while larger enterprises appreciate the data sovereignty and customization options. DevOps teams favor this setup for CI/CD integrations, IT departments use it for system monitoring and alerting workflows, and marketing teams leverage it for lead nurturing and customer communication automation.

Key Features

  • Visual workflow editor with 350+ pre-built service integrations including Slack, Google Workspace, AWS, and Salesforce
  • Queue-based execution system using Redis Bull queues for horizontal scaling and reliable workflow processing
  • PostgreSQL database backend providing ACID compliance for workflow definitions, execution history, and credential storage
  • Dedicated worker processes for handling long-running workflows without blocking the main application interface
  • Webhook triggers supporting real-time workflow initiation from external services and custom applications
  • Advanced error handling with configurable retry policies, exponential backoff, and workflow branching based on success/failure
  • Credential management system with AES encryption for securely storing API keys and authentication tokens
  • Execution history with detailed logs, performance metrics, and workflow debugging capabilities

Common Use Cases

  • 1E-commerce order processing automation connecting Shopify, inventory systems, shipping providers, and customer communication tools
  • 2Lead nurturing workflows that sync CRM data, trigger email sequences, and update marketing automation platforms based on user behavior
  • 3IT monitoring and incident response automating Prometheus alerts, creating Jira tickets, and notifying teams via Slack or PagerDuty
  • 4Data synchronization between business systems like syncing customer data from Salesforce to marketing tools and accounting software
  • 5Social media management workflows that cross-post content, monitor mentions, and aggregate analytics across multiple platforms
  • 6DevOps CI/CD pipeline integration triggering deployments, running tests, and sending notifications based on Git repository changes
  • 7Customer support automation routing tickets, escalating issues, and updating knowledge bases based on common inquiries

Prerequisites

  • Minimum 1GB RAM (2GB+ recommended) to support n8n application, PostgreSQL database, and Redis queue processing
  • Port 5678 available for n8n web interface access and API endpoints
  • Basic understanding of workflow automation concepts and API integrations for creating effective n8n workflows
  • Knowledge of environment variable configuration for setting up database connections and authentication credentials
  • Familiarity with Docker networking concepts for troubleshooting inter-container communication issues
  • Understanding of backup strategies for PostgreSQL data and n8n workflow configurations

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 n8n:
3 image: n8nio/n8n:latest
4 environment:
5 - N8N_BASIC_AUTH_ACTIVE=true
6 - N8N_BASIC_AUTH_USER=${N8N_USER}
7 - N8N_BASIC_AUTH_PASSWORD=${N8N_PASSWORD}
8 - DB_TYPE=postgresdb
9 - DB_POSTGRESDB_HOST=postgres
10 - DB_POSTGRESDB_PORT=5432
11 - DB_POSTGRESDB_DATABASE=n8n
12 - DB_POSTGRESDB_USER=${POSTGRES_USER}
13 - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
14 - EXECUTIONS_MODE=queue
15 - QUEUE_BULL_REDIS_HOST=redis
16 - N8N_ENCRYPTION_KEY=${ENCRYPTION_KEY}
17 volumes:
18 - n8n-data:/home/node/.n8n
19 ports:
20 - "5678:5678"
21 depends_on:
22 - postgres
23 - redis
24 networks:
25 - n8n-network
26 restart: unless-stopped
27
28 n8n-worker:
29 image: n8nio/n8n:latest
30 command: worker
31 environment:
32 - DB_TYPE=postgresdb
33 - DB_POSTGRESDB_HOST=postgres
34 - DB_POSTGRESDB_PORT=5432
35 - DB_POSTGRESDB_DATABASE=n8n
36 - DB_POSTGRESDB_USER=${POSTGRES_USER}
37 - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
38 - EXECUTIONS_MODE=queue
39 - QUEUE_BULL_REDIS_HOST=redis
40 - N8N_ENCRYPTION_KEY=${ENCRYPTION_KEY}
41 depends_on:
42 - n8n
43 - postgres
44 - redis
45 networks:
46 - n8n-network
47 restart: unless-stopped
48
49 postgres:
50 image: postgres:15
51 environment:
52 - POSTGRES_USER=${POSTGRES_USER}
53 - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
54 - POSTGRES_DB=n8n
55 volumes:
56 - postgres-data:/var/lib/postgresql/data
57 networks:
58 - n8n-network
59 restart: unless-stopped
60
61 redis:
62 image: redis:alpine
63 volumes:
64 - redis-data:/data
65 networks:
66 - n8n-network
67 restart: unless-stopped
68
69volumes:
70 n8n-data:
71 postgres-data:
72 redis-data:
73
74networks:
75 n8n-network:
76 driver: bridge

.env Template

.env
1# n8n Automation
2N8N_USER=admin
3N8N_PASSWORD=secure_admin_password
4POSTGRES_USER=n8n
5POSTGRES_PASSWORD=secure_postgres_password
6ENCRYPTION_KEY=your-encryption-key
7
8# Generate key: openssl rand -hex 32

Usage Notes

  1. 1Web UI at http://localhost:5678
  2. 2300+ integrations available
  3. 3Visual workflow editor
  4. 4Queue mode for scaling
  5. 5Self-hosted Zapier alternative

Individual Services(4 services)

Copy individual services to mix and match with your existing compose files.

n8n
n8n:
  image: n8nio/n8n:latest
  environment:
    - N8N_BASIC_AUTH_ACTIVE=true
    - N8N_BASIC_AUTH_USER=${N8N_USER}
    - N8N_BASIC_AUTH_PASSWORD=${N8N_PASSWORD}
    - DB_TYPE=postgresdb
    - DB_POSTGRESDB_HOST=postgres
    - DB_POSTGRESDB_PORT=5432
    - DB_POSTGRESDB_DATABASE=n8n
    - DB_POSTGRESDB_USER=${POSTGRES_USER}
    - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
    - EXECUTIONS_MODE=queue
    - QUEUE_BULL_REDIS_HOST=redis
    - N8N_ENCRYPTION_KEY=${ENCRYPTION_KEY}
  volumes:
    - n8n-data:/home/node/.n8n
  ports:
    - "5678:5678"
  depends_on:
    - postgres
    - redis
  networks:
    - n8n-network
  restart: unless-stopped
n8n-worker
n8n-worker:
  image: n8nio/n8n:latest
  command: worker
  environment:
    - DB_TYPE=postgresdb
    - DB_POSTGRESDB_HOST=postgres
    - DB_POSTGRESDB_PORT=5432
    - DB_POSTGRESDB_DATABASE=n8n
    - DB_POSTGRESDB_USER=${POSTGRES_USER}
    - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
    - EXECUTIONS_MODE=queue
    - QUEUE_BULL_REDIS_HOST=redis
    - N8N_ENCRYPTION_KEY=${ENCRYPTION_KEY}
  depends_on:
    - n8n
    - postgres
    - redis
  networks:
    - n8n-network
  restart: unless-stopped
postgres
postgres:
  image: postgres:15
  environment:
    - POSTGRES_USER=${POSTGRES_USER}
    - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    - POSTGRES_DB=n8n
  volumes:
    - postgres-data:/var/lib/postgresql/data
  networks:
    - n8n-network
  restart: unless-stopped
redis
redis:
  image: redis:alpine
  volumes:
    - redis-data:/data
  networks:
    - n8n-network
  restart: unless-stopped

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 n8n:
5 image: n8nio/n8n:latest
6 environment:
7 - N8N_BASIC_AUTH_ACTIVE=true
8 - N8N_BASIC_AUTH_USER=${N8N_USER}
9 - N8N_BASIC_AUTH_PASSWORD=${N8N_PASSWORD}
10 - DB_TYPE=postgresdb
11 - DB_POSTGRESDB_HOST=postgres
12 - DB_POSTGRESDB_PORT=5432
13 - DB_POSTGRESDB_DATABASE=n8n
14 - DB_POSTGRESDB_USER=${POSTGRES_USER}
15 - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
16 - EXECUTIONS_MODE=queue
17 - QUEUE_BULL_REDIS_HOST=redis
18 - N8N_ENCRYPTION_KEY=${ENCRYPTION_KEY}
19 volumes:
20 - n8n-data:/home/node/.n8n
21 ports:
22 - "5678:5678"
23 depends_on:
24 - postgres
25 - redis
26 networks:
27 - n8n-network
28 restart: unless-stopped
29
30 n8n-worker:
31 image: n8nio/n8n:latest
32 command: worker
33 environment:
34 - DB_TYPE=postgresdb
35 - DB_POSTGRESDB_HOST=postgres
36 - DB_POSTGRESDB_PORT=5432
37 - DB_POSTGRESDB_DATABASE=n8n
38 - DB_POSTGRESDB_USER=${POSTGRES_USER}
39 - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
40 - EXECUTIONS_MODE=queue
41 - QUEUE_BULL_REDIS_HOST=redis
42 - N8N_ENCRYPTION_KEY=${ENCRYPTION_KEY}
43 depends_on:
44 - n8n
45 - postgres
46 - redis
47 networks:
48 - n8n-network
49 restart: unless-stopped
50
51 postgres:
52 image: postgres:15
53 environment:
54 - POSTGRES_USER=${POSTGRES_USER}
55 - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
56 - POSTGRES_DB=n8n
57 volumes:
58 - postgres-data:/var/lib/postgresql/data
59 networks:
60 - n8n-network
61 restart: unless-stopped
62
63 redis:
64 image: redis:alpine
65 volumes:
66 - redis-data:/data
67 networks:
68 - n8n-network
69 restart: unless-stopped
70
71volumes:
72 n8n-data:
73 postgres-data:
74 redis-data:
75
76networks:
77 n8n-network:
78 driver: bridge
79EOF
80
81# 2. Create the .env file
82cat > .env << 'EOF'
83# n8n Automation
84N8N_USER=admin
85N8N_PASSWORD=secure_admin_password
86POSTGRES_USER=n8n
87POSTGRES_PASSWORD=secure_postgres_password
88ENCRYPTION_KEY=your-encryption-key
89
90# Generate key: openssl rand -hex 32
91EOF
92
93# 3. Start the services
94docker compose up -d
95
96# 4. View logs
97docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/n8n-automation/run | bash

Troubleshooting

  • n8n interface shows 'Database connection failed': Verify POSTGRES_USER and POSTGRES_PASSWORD environment variables match between n8n and postgres containers
  • Workflows fail to execute with 'Queue connection timeout': Check that Redis container is running and QUEUE_BULL_REDIS_HOST points to the correct Redis service name
  • n8n-worker container crashes with 'Encryption key mismatch': Ensure N8N_ENCRYPTION_KEY environment variable is identical across n8n and n8n-worker containers
  • Workflows execute slowly or time out: Increase worker container resources or add additional n8n-worker containers for better load distribution
  • PostgreSQL container fails to start with 'Data directory not empty': Remove existing postgres-data volume or set POSTGRES_DB environment variable correctly
  • n8n shows 'Authentication failed' on startup: Generate a strong N8N_ENCRYPTION_KEY using openssl rand -base64 32 and update environment variables

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space