## β
1. Folder Structure
Run this to create the required folders:
```bash
mkdir -p ~/Documents/projects/llm-tools/n8n/{data,postgres-data,redis-data}
cd ~/Documents/projects/llm-tools/n8n
```
---
## ποΈ 2. `.env` File
Create a file at `~/Documents/projects/llm-tools/n8n/.env`:
```env
# PostgreSQL
POSTGRES_USER=n8n
POSTGRES_PASSWORD=n8n_pass_123
POSTGRES_DB=n8n
# n8n Basic Auth
N8N_BASIC_AUTH_USER=n8nadmin
N8N_BASIC_AUTH_PASSWORD=SuperSecretPassword123
# Timezone
GENERIC_TIMEZONE=Asia/Kolkata
```
You can always rotate/change these values later.
---
## π³ 3. `docker-compose.yml`
Create this file at `~/Documents/projects/llm-tools/n8n/docker-compose.yml`:
```yaml
services:
postgres:
image: postgres:15
container_name: n8n_postgres
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- ./postgres-data:/var/lib/postgresql/data
redis:
image: redis:6-alpine
container_name: n8n_redis
restart: unless-stopped
volumes:
- ./redis-data:/data
n8n:
image: n8nio/n8n:latest
container_name: n8n
restart: unless-stopped
depends_on:
- postgres
- redis
ports:
- "5678:5678"
environment:
# Timezone and Host
- GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
- N8N_HOST=localhost
- N8N_PORT=5678
- N8N_PROTOCOL=http
- N8N_EDITOR_BASE_URL=http://localhost:5678
# Auth
- N8N_BASIC_AUTH_ACTIVE=true
- N8N_BASIC_AUTH_USER=${N8N_BASIC_AUTH_USER}
- N8N_BASIC_AUTH_PASSWORD=${N8N_BASIC_AUTH_PASSWORD}
# PostgreSQL DB
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PORT=5432
- DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
- DB_POSTGRESDB_USER=${POSTGRES_USER}
- DB_POSTGRESDB_PASSWORD=${POSTGRES_PASSWORD}
# Redis Queue Mode
- QUEUE_MODE=redis
- QUEUE_REDIS_HOST=redis
- QUEUE_REDIS_PORT=6379
- QUEUE_REDIS_DB=0
# Optional Features
- N8N_COMMUNITY_NODES_ENABLED=true
- N8N_ALLOW_UNSAFE_EXECUTIONS=true
- N8N_ENABLE_EXTERNAL_COMMUNICATION=true
- N8N_PERSONALIZATION_ENABLED=true
volumes:
- ./data:/home/node/.n8n
```
---
## π 4. Set Correct File Permissions
Ensure the `data` directory is owned by the container user:
```bash
sudo chown -R 1000:1000 ~/Documents/projects/llm-tools/n8n/data
```
---
## π 5. Start Everything
From the `n8n` project directory:
```bash
cd ~/Documents/projects/llm-tools/n8n
docker compose --env-file .env up -d
```
To verify containers:
```bash
docker compose ps
```
Access the web UI:
π [http://localhost:5678](http://localhost:5678/)
Login using:
- **Username:** `n8nadmin`
- **Password:** `SuperSecretPassword123`
(or whatever you defined in `.env`)
---
## β
Summary of Benefits
|Feature|Enabled|
|---|---|
|PostgreSQL for DB|β
|
|Redis Queue Mode|β
|
|External volumes|β
|
|Passwords in `.env`|β
|
|Community Nodes|β
|
|Basic Auth login|β
|
|Unsafe exec (for dev)|β
|