Automated n8n Docker setup with Cloudflare Tunnel, Postgres, file access, and Code node libraries

I made a small repo for quickly running n8n locally with Docker and exposing it through a Cloudflare Tunnel:

https://github.com/akshaynexus/n8n-docker-cloudflared

The goal is to make a useful local n8n setup with very little config. It includes n8n, Postgres, persistent Docker volumes, Cloudflared, local file access through a mounted ./files directory, and a custom n8n image with common npm packages already installed for Code nodes.

It supports two ways to use it.

Option 1: automatic setup script

Clone the repo, create your .env, then run:

cp .env.example .env
./scripts/start.sh

The script starts a Cloudflare quick tunnel, extracts the generated trycloudflare.com URL, updates .env, and starts n8n with the correct webhook settings.

It prints both:

http://localhost:5678/
https://xxxx.trycloudflare.com/

This is the easiest path if you just want n8n running with webhooks working quickly.

Option 2: manual setup

You can also start everything manually:

cp .env.example .env
docker compose up -d --build
docker compose logs -f cloudflared

Cloudflared will print a URL like:

https://xxxx.trycloudflare.com

Then update .env:

N8N_HOST=xxxx.trycloudflare.com
N8N_PROTOCOL=https
WEBHOOK_URL=https://xxxx.trycloudflare.com/

Restart the stack:

docker compose up -d

Then open n8n using either the Cloudflare URL or:

http://localhost:5678/

The setup also mounts a local files/ folder into n8n as /files, so workflows can read and write files there. It also preinstalls useful Code node libraries like axios, lodash, zod, moment, dayjs, and uuid.

Quick tunnels are mainly for local testing and webhook development. For long-running usage, the repo also includes notes for switching to a named Cloudflare Tunnel with your own domain.

2 Likes

Great writeup! This will help newbies in the docker setup.

Do you intend to include setup for python code as well?

1 Like

Could you explain by setup for python code aswell? cause this is mostly just a docker file with a bash script to autoamte the docker setup via a non authenticated cloudflare tunnel

Your title mentioned code node libraries, I was expecting ability to run javascript as well as python code. Maybe I had over-expectations…

IF n8n supports it then it should be possible,its msotly a helper repo to simplify hosting via docker with a cloudflare tunnel with config mainyl supporting custom community nodes and some dependenceis and excute command node enabled by default for advacned users