Skip to content

marcodellorto/n8n-local-stack

Repository files navigation

n8n Local Stack

This project runs n8n locally with PostgreSQL for persistence and cloudflared to expose the instance through a Cloudflare Tunnel token.

Services

  • postgres: persistent database for n8n
  • n8n: workflow automation UI and runtime
  • cloudflared: outbound tunnel connector for public exposure through Cloudflare

Prerequisites

  • Docker
  • Docker Compose
  • A Cloudflare account and a zone you control

Quick start

  1. Copy the environment template:

    cp .env.example .env
  2. Copy the Docker Compose override template:

    cp docker-compose.override.yml.dist docker-compose.override.yml
  3. Create the PostgreSQL data directory before the first start:

    mkdir -p .docker/postgres/data

    Keep this directory empty before PostgreSQL initializes, otherwise the container may fail to start.

  4. Edit .env and set at least:

    • POSTGRES_PASSWORD
    • N8N_ENCRYPTION_KEY
    • N8N_BASIC_AUTH_USER
    • N8N_BASIC_AUTH_PASSWORD
    • CLOUDFLARE_TUNNEL_TOKEN
  5. Start the local stack:

    docker compose up -d
  6. Open http://localhost:5678 for local access.

Environment variables

The main settings live in .env.

  • N8N_HOST, N8N_PROTOCOL, N8N_EDITOR_BASE_URL: editor URL settings
  • WEBHOOK_URL: public base URL used by n8n for webhooks
  • N8N_BASIC_AUTH_*: default protection for the internet-facing instance
  • CLOUDFLARE_TUNNEL_TOKEN: token used by the cloudflared container
  • CLOUDFLARE_PUBLIC_HOSTNAME: placeholder for your public DNS name

Cloudflare tunnel setup

  1. In Cloudflare Zero Trust, create a new tunnel.

  2. Choose the Docker connector flow.

  3. Create a public hostname such as n8n.example.com that points to http://n8n:5678.

  4. Copy the generated tunnel token into .env as CLOUDFLARE_TUNNEL_TOKEN.

  5. Set:

    • CLOUDFLARE_PUBLIC_HOSTNAME=n8n.example.com
    • WEBHOOK_URL=https://n8n.example.com/
    • N8N_EDITOR_BASE_URL=https://n8n.example.com/
  6. Start or restart the stack:

    docker compose up -d

Cloudflare will terminate HTTPS. The local n8n container still listens on plain HTTP inside Docker.

Common commands

Start:

docker compose up -d

Stop:

docker compose down

Stop and remove volumes:

docker compose down -v

Logs:

docker compose logs -f n8n postgres cloudflared

Security notes

  • Keep .env private.
  • Use a strong random value for N8N_ENCRYPTION_KEY.
  • Do not expose n8n publicly without authentication.

Troubleshooting

  • If n8n cannot start, check that PostgreSQL is healthy with docker compose ps.
  • If webhooks use the wrong URL, confirm WEBHOOK_URL and N8N_EDITOR_BASE_URL.
  • If the public hostname does not connect, verify the tunnel is healthy in the Cloudflare dashboard and inspect docker compose logs cloudflared.

Releases

No releases published

Contributors