version: "3.8"

services:
  postgres:
    image: postgres:16
    container_name: n8n-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: n8n
      POSTGRES_PASSWORD: CHANGE_ME_STRONG_PASSWORD
      POSTGRES_DB: n8n
    volumes:
      - /volume1/docker/docker_projects/n8n/postgres_data:/var/lib/postgresql/data

  n8n:
    image: docker.n8n.io/n8nio/n8n:latest
    container_name: n8n
    restart: unless-stopped
    depends_on:
      - postgres
    ports:
      - "3300:5678"
    environment:
      # ===== 时区 =====
      TZ: Asia/Shanghai
      GENERIC_TIMEZONE: Asia/Shanghai

      # ===== 权限 & 运行机制（官方参数）=====
      N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS: "true"
      N8N_RUNNERS_ENABLED: "true"
      N8N_SECURE_COOKIE: "false"

      # ===== 数据库（Postgres）=====
      DB_TYPE: postgresdb
      DB_POSTGRESDB_HOST: postgres
      DB_POSTGRESDB_PORT: 5432
      DB_POSTGRESDB_DATABASE: n8n
      DB_POSTGRESDB_USER: n8n
      DB_POSTGRESDB_PASSWORD: CHANGE_ME_STRONG_PASSWORD
      DB_POSTGRESDB_SCHEMA: public

      # ===== 强烈建议：首次就固定（不要后面改）=====
      N8N_ENCRYPTION_KEY: "XepzhV7nMbjYN"

      # 可选：限制注册/简易认证（看你的版本/用法）
      N8N_BASIC_AUTH_ACTIVE: "true"
      N8N_BASIC_AUTH_USER: "Kun"
      N8N_BASIC_AUTH_PASSWORD: "XepzhV7nMbjYN"


    volumes:
      - /volume1/docker/docker_projects/n8n/n8n_data:/home/node/.n8n
