Part 5: Local Deployment

Run n8n locally using Docker Compose and expose it using a Cloudflare Quick Tunnel.

16. Local Deployment with Docker

Up to this point, we have been using n8n through the browser or cloud environment.

We can also run n8n locally on our own computer using Docker.

Final setup:

Docker → n8n → Cloudflare Quick Tunnel → Public temporary URL

16.1 Install Docker

Windows

winget install --id Docker.DockerDesktop -e

macOS

brew install --cask docker

Ubuntu / Debian

sudo apt update

sudo apt install -y docker.io docker-compose-plugin

sudo systemctl enable --now docker

Arch Linux

sudo pacman -Syu docker docker-compose

sudo systemctl enable --now docker

Optional Docker Group Setup on Linux

sudo usermod -aG docker $USER

Log out and log back in after adding your user to the Docker group.

16.2 Create the n8n Folder

mkdir n8n

cd n8n

16.3 Create docker-compose.yml

Inside the n8n folder, create a file named:

docker-compose.yml

Add the following configuration:

services:
  n8n:
    image: docker.n8n.io/n8nio/n8n
    container_name: n8n
    ports:
      - "5678:5678"

    environment:
      - N8N_SECURE_COOKIE=false
      - WEBHOOK_URL=http://localhost:5678/

    volumes:
      - n8n_data:/home/node/.n8n

    restart: unless-stopped

volumes:
  n8n_data:

The volume allows your n8n data to remain available even when the container is restarted.

16.4 Start n8n

docker compose up -d

Check whether the container is running:

docker compose ps

You can also check the logs:

docker compose logs n8n

16.5 Open n8n

Once the container is running, open:

http://localhost:5678

This opens the locally running n8n instance.

16.6 Install Cloudflared

To temporarily expose our local n8n instance to the internet, we can use a Cloudflare Quick Tunnel.

Windows

winget install --id Cloudflare.cloudflared

macOS

brew install cloudflared

Ubuntu / Debian

Follow the official Cloudflare installation instructions for your distribution.

Arch Linux

yay -S cloudflared

Check the installation:

cloudflared --version

16.7 Create a Cloudflare Quick Tunnel

Make sure n8n is already running.

Then run:

cloudflared tunnel --url http://localhost:5678

Cloudflare will generate a temporary URL.

Example:

https://hero-rio-stationery-appropriations.trycloudflare.com

16.8 Update WEBHOOK_URL

Open your docker-compose.yml file.

Replace:

WEBHOOK_URL=http://localhost:5678/

with your generated Cloudflare URL:

WEBHOOK_URL=https://your-generated-url.trycloudflare.com/

Save the file.

16.9 Restart n8n

docker compose down

docker compose up -d

Now open your Cloudflare URL.

16.10 Create the n8n Owner Account

When opening n8n for the first time, you will be asked to create the initial owner account.

Follow the instructions shown by n8n.

16.11 Test the Workshop Workflow

  1. Open the n8n instance.
  2. Open the workshop workflow.
  3. Submit the student form.
  4. Check the AI response.
  5. Check Gmail.
  6. Check Discord if Discord automation is enabled.
You now have a locally running n8n AI automation system.

16.12 Useful Docker Commands

Start n8n

docker compose up -d

Stop n8n

docker compose down

Restart n8n

docker compose restart

Check Status

docker compose ps

View Logs

docker compose logs n8n

Pull Latest Image

docker compose pull

16.13 Stop the Cloudflare Tunnel

The Quick Tunnel runs in your terminal.

To stop it, press:

Ctrl + C

When you start a new Quick Tunnel, Cloudflare may generate a new URL.

16.14 If the URL Changes

Quick Tunnel URLs are temporary.

If you receive a new URL, update the WEBHOOK_URL inside your Docker Compose file.

WEBHOOK_URL=https://new-url.trycloudflare.com/

Then recreate the container:

docker compose down

docker compose up -d

16.15 Important Notes

  • Cloudflare Quick Tunnel URLs are temporary.
  • Quick Tunnels are intended for testing and development.
  • Do not expose sensitive information.
  • Never share API keys or bot tokens.
  • Do not treat a Quick Tunnel as a production deployment.

16.16 Final Architecture

Student → Form → n8n → Groq AI → Gmail + Discord

Workshop Complete!

We have built an AI-powered automation using n8n, connected it to Groq, Gmail and Discord, and learned how to run n8n locally using Docker.

Back to Workshop Home

← Return to Workshop Home