docker.recipes

n8n Workflow Automation

intermediate

n8n workflow automation platform with PostgreSQL for workflow data persistence.

Overview

n8n is a fair-code workflow automation platform that emerged as a powerful self-hosted alternative to services like Zapier and Microsoft Power Automate. Built with a visual workflow designer, n8n enables users to create complex automation sequences connecting over 350 different services and applications without requiring extensive coding knowledge. The platform supports custom JavaScript nodes, webhook triggers, and advanced error handling, making it suitable for both simple task automation and sophisticated business process workflows. This stack combines n8n with PostgreSQL to create a production-ready automation platform with persistent data storage. While n8n can operate with SQLite for development, PostgreSQL provides the ACID compliance, concurrent user support, and data integrity required for business-critical workflows. The PostgreSQL backend stores workflow definitions, execution history, credentials, and user data, ensuring that complex automation sequences remain reliable and auditable over time. This configuration targets organizations and teams seeking workflow automation independence without recurring SaaS fees. DevOps teams can deploy internal automation workflows, marketing departments can orchestrate multi-channel campaigns, and data engineers can build ETL pipelines with visual interfaces. The self-hosted approach provides complete control over sensitive credentials and workflow logic while offering the scalability to handle thousands of workflow executions.

Key Features

  • Visual workflow builder with drag-and-drop interface for creating complex automation sequences
  • 350+ pre-built integrations including popular services like Slack, GitHub, Google Sheets, and AWS
  • Custom JavaScript code nodes for advanced data transformation and business logic
  • Webhook endpoints for triggering workflows from external applications and services
  • Scheduled workflow execution with cron-like syntax and timezone support
  • Comprehensive execution history with detailed logs stored in PostgreSQL
  • Credential management system with encrypted storage and team sharing capabilities
  • Error handling and retry mechanisms with exponential backoff and custom error workflows

Common Use Cases

  • 1DevOps automation for deployment notifications, incident response, and infrastructure monitoring alerts
  • 2Marketing automation workflows connecting CRM systems, email platforms, and social media management tools
  • 3Data synchronization between business applications like syncing leads from web forms to CRM and project management tools
  • 4E-commerce automation for order processing, inventory management, and customer communication workflows
  • 5Content management workflows for publishing blog posts, social media updates, and documentation across multiple platforms
  • 6IT service management automation for ticket routing, user provisioning, and system health monitoring
  • 7Financial data processing including invoice generation, expense tracking, and automated reporting workflows

Prerequisites

  • Docker and Docker Compose installed with support for health checks and depends_on conditions
  • Minimum 768MB RAM available (256MB for PostgreSQL, 512MB for n8n workflow execution)
  • Port 5678 available for n8n web interface access
  • Basic understanding of workflow concepts and API integrations for building automation sequences
  • Environment variable configuration for database credentials and authentication settings
  • SSL/TLS certificate if exposing n8n to external webhook triggers over HTTPS

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 container_name: n8n
5 environment:
6 - N8N_HOST=${N8N_HOST}
7 - N8N_PORT=5678
8 - N8N_PROTOCOL=http
9 - NODE_ENV=production
10 - WEBHOOK_URL=${WEBHOOK_URL}
11 - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
12 - DB_TYPE=postgresdb
13 - DB_POSTGRESDB_HOST=postgres
14 - DB_POSTGRESDB_PORT=5432
15 - DB_POSTGRESDB_DATABASE=n8n
16 - DB_POSTGRESDB_USER=${POSTGRES_USER}
17 - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
18 - N8N_BASIC_AUTH_ACTIVE=true
19 - N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER}
20 - N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD}
21 ports:
22 - "5678:5678"
23 volumes:
24 - n8n_data:/home/node/.n8n
25 depends_on:
26 postgres:
27 condition: service_healthy
28 networks:
29 - n8n-network
30
31 postgres:
32 image: postgres:16-alpine
33 container_name: n8n-db
34 environment:
35 - POSTGRES_USER=${POSTGRES_USER}
36 - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
37 - POSTGRES_DB=n8n
38 volumes:
39 - postgres_data:/var/lib/postgresql/data
40 healthcheck:
41 test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d n8n"]
42 interval: 10s
43 timeout: 5s
44 retries: 5
45 networks:
46 - n8n-network
47
48volumes:
49 n8n_data:
50 postgres_data:
51
52networks:
53 n8n-network:
54 driver: bridge

.env Template

.env
1# n8n Workflow Automation
2N8N_HOST=localhost
3WEBHOOK_URL=http://localhost:5678
4GENERIC_TIMEZONE=UTC
5POSTGRES_USER=n8n
6POSTGRES_PASSWORD=n8n_password
7N8N_BASIC_AUTH_USER=admin
8N8N_BASIC_AUTH_PASSWORD=changeme

Usage Notes

  1. 1Editor at http://localhost:5678
  2. 2400+ integrations available
  3. 3Self-hosted Zapier alternative
  4. 4Supports webhooks and schedules
  5. 5Create custom nodes with JavaScript

Individual Services(2 services)

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

n8n
n8n:
  image: n8nio/n8n:latest
  container_name: n8n
  environment:
    - N8N_HOST=${N8N_HOST}
    - N8N_PORT=5678
    - N8N_PROTOCOL=http
    - NODE_ENV=production
    - WEBHOOK_URL=${WEBHOOK_URL}
    - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    - 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}
    - N8N_BASIC_AUTH_ACTIVE=true
    - N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER}
    - N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD}
  ports:
    - "5678:5678"
  volumes:
    - n8n_data:/home/node/.n8n
  depends_on:
    postgres:
      condition: service_healthy
  networks:
    - n8n-network
postgres
postgres:
  image: postgres:16-alpine
  container_name: n8n-db
  environment:
    - POSTGRES_USER=${POSTGRES_USER}
    - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    - POSTGRES_DB=n8n
  volumes:
    - postgres_data:/var/lib/postgresql/data
  healthcheck:
    test:
      - CMD-SHELL
      - pg_isready -U ${POSTGRES_USER} -d n8n
    interval: 10s
    timeout: 5s
    retries: 5
  networks:
    - n8n-network

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 n8n:
5 image: n8nio/n8n:latest
6 container_name: n8n
7 environment:
8 - N8N_HOST=${N8N_HOST}
9 - N8N_PORT=5678
10 - N8N_PROTOCOL=http
11 - NODE_ENV=production
12 - WEBHOOK_URL=${WEBHOOK_URL}
13 - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
14 - DB_TYPE=postgresdb
15 - DB_POSTGRESDB_HOST=postgres
16 - DB_POSTGRESDB_PORT=5432
17 - DB_POSTGRESDB_DATABASE=n8n
18 - DB_POSTGRESDB_USER=${POSTGRES_USER}
19 - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
20 - N8N_BASIC_AUTH_ACTIVE=true
21 - N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER}
22 - N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD}
23 ports:
24 - "5678:5678"
25 volumes:
26 - n8n_data:/home/node/.n8n
27 depends_on:
28 postgres:
29 condition: service_healthy
30 networks:
31 - n8n-network
32
33 postgres:
34 image: postgres:16-alpine
35 container_name: n8n-db
36 environment:
37 - POSTGRES_USER=${POSTGRES_USER}
38 - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
39 - POSTGRES_DB=n8n
40 volumes:
41 - postgres_data:/var/lib/postgresql/data
42 healthcheck:
43 test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d n8n"]
44 interval: 10s
45 timeout: 5s
46 retries: 5
47 networks:
48 - n8n-network
49
50volumes:
51 n8n_data:
52 postgres_data:
53
54networks:
55 n8n-network:
56 driver: bridge
57EOF
58
59# 2. Create the .env file
60cat > .env << 'EOF'
61# n8n Workflow Automation
62N8N_HOST=localhost
63WEBHOOK_URL=http://localhost:5678
64GENERIC_TIMEZONE=UTC
65POSTGRES_USER=n8n
66POSTGRES_PASSWORD=n8n_password
67N8N_BASIC_AUTH_USER=admin
68N8N_BASIC_AUTH_PASSWORD=changeme
69EOF
70
71# 3. Start the services
72docker compose up -d
73
74# 4. View logs
75docker 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-workflow-automation/run | bash

Troubleshooting

  • n8n container fails to start with database connection error: Verify PostgreSQL container is healthy and environment variables DB_POSTGRESDB_USER and DB_POSTGRESDB_PASSWORD match POSTGRES_USER and POSTGRES_PASSWORD
  • Workflow executions fail with 'Workflow could not be started' error: Check n8n container logs for memory issues and increase Docker memory allocation if workflows involve large data processing
  • Webhooks return 404 or timeout errors: Ensure WEBHOOK_URL environment variable matches your external domain and that firewall rules allow inbound connections to port 5678
  • PostgreSQL container exits with permission denied errors: Verify the postgres_data volume has correct ownership or delete the volume to reinitialize with proper permissions
  • n8n interface shows 'Cannot connect to database' after restart: Wait for PostgreSQL health check to pass or check if database initialization completed by examining postgres container logs
  • Custom nodes fail to load with JavaScript execution errors: Verify NODE_ENV is set to production and check that custom node dependencies are properly installed in the n8n container

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