## βœ… 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)|βœ…|