commit bcf65145641882e679affca15240fa9871ffaec9 Author: muzi <444136347@qq.com> Date: Mon Jan 26 14:17:15 2026 +0800 first commit diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e455aa6 --- /dev/null +++ b/.env.example @@ -0,0 +1,10 @@ +# n8n 访问端口(本机如果 5678 冲突就改成 5679/5680...) +N8N_PORT=5678 + +# 时区 +TZ=Asia/Shanghai + +# Postgres(默认即可) +POSTGRES_USER=n8n +POSTGRES_PASSWORD=n8npass +POSTGRES_DB=n8n \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0525e16 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.env +n8n-data/ +postgres-data/ +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..4335cac --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# n8n 本地运行(Docker Compose) + +## 前置要求 +- 已安装并启动 Docker Desktop +- 终端能执行: + - docker -v + - docker compose version + +## 安装与启动 +```bash +git clone <你的仓库地址> +cd n8n-local + +cp .env.example .env +# 如端口冲突,编辑 .env 修改 N8N_PORT=5679 + +docker compose up -d +docker compose ps +``` + +备注: +- 当前固定使用 `n8nio/n8n:2.2.4` +- `postgres` 加了健康检查,`n8n` 会等待数据库就绪后再启动 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6e73d36 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +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} + TZ: ${TZ} + volumes: + - ./postgres-data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] + interval: 10s + timeout: 5s + retries: 5 + + n8n: + image: n8nio/n8n:2.2.4 + container_name: n8n + restart: unless-stopped + ports: + - "${N8N_PORT}:5678" + environment: + 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} + TZ: ${TZ} + volumes: + - ./n8n-data:/home/node/.n8n + depends_on: + postgres: + condition: service_healthy