services: db: image: postgres:16-alpine restart: always environment: - POSTGRES_USER=${POSTGRES_USER:-n8n_user} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-n8n_password} - POSTGRES_DB=${POSTGRES_DB:-n8n_db} volumes: - ${POSTGRES_DATA_PATH:-postgres_data}:/var/lib/postgresql/data healthcheck: # Note: We use the same fallbacks here to ensure the check matches the credentials test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-n8n_user} -d ${POSTGRES_DB:-n8n_db}"] interval: 5s timeout: 5s retries: 5 n8n: image: n8nio/n8n:latest restart: always ports: - "${N8N_PORT:-5678}:5678" environment: - DB_TYPE=postgresdb - DB_POSTGRESDB_HOST=db - DB_POSTGRESDB_PORT=5432 - DB_POSTGRESDB_DATABASE=${POSTGRES_DB:-n8n_db} - DB_POSTGRESDB_USER=${POSTGRES_USER:-n8n_user} - DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD:-n8n_password} - N8N_ENCRYPTION_KEY=${N8N_ENCRYPTION_KEY:-default_encryption_key_change_me} - GENERIC_TIMEZONE=${GENERIC_TIMEZONE:-UTC} - TZ=${GENERIC_TIMEZONE:-UTC} - N8N_HOST=${SUBDOMAIN:-n8n}.${DOMAIN_NAME:-localhost} - WEBHOOK_URL=https://${SUBDOMAIN:-n8n}.${DOMAIN_NAME:-localhost}/ volumes: - ${N8N_DATA_PATH:-n8n_data}:/home/node/.n8n depends_on: db: condition: service_healthy volumes: n8n_data: postgres_data: