Back to articles
AI Agents

Deploy n8n for free with Docker and ngrok

Deploy n8n for free with Docker and ngrok accessible everywhere without hosting costs.

Daryl Ngako

Deploy n8n for free with Docker and ngrok

Getting started with automation with n8n can quickly become frustrating when you realize that cloud hosting is expensive, or that simple local use restricts essential functionalities such as webhooks.

In this comprehensive guide, I'll show you how to remove these barriers. You will learn how to deploy n8n locally, make it accessible from anywhere and secure your data all for free thanks to the power of Docker and ngrok.

What is N8N?

n8n is an open-source workflow automation platform designed to connect tools together and orchestrate business processes.

Imagine an intelligent assistant capable of:

  • Exchange with your prospects on WhatsApp 24/7.
  • Book appointments automatically in your calendar.
  • Synchronize data in your CRM (Google Sheets, Airtable, Notion).
  • Alert a human only in the event of a complex request.

It is the open-source equivalent of Zapier or Make, offering freedom total technique without the costs per execution.

Here is an overview of the prices of their Cloud offer:

Pricing n8n

The observation is clear: 20$ / month for only 5 active workflows, it's a heavy investment when you're starting out. Fortunately, self-hosting allows us to break these limitations.

The Localhost problem

When you install n8n on localhost, everything seems to work fine... until you face these three major obstacles:

  • Webhooks incompatibility: Platforms like Gmail, YouTube, Stripe or Telegram cannot send data to http://localhost:5678. They need a valid public URL.

  • HTTPS requirement: The majority of modern APIs require HTTPS encrypted connections. Your localhost does not provide that.

  • Limited accessibility: Impossible to trigger your workflows from another device (phone, other PC) or to share access to your n8n editor.

In summary: without a public domain, n8n remains an isolated tool on your machine, unable to communicate with the outside world.

ngrok: the bridge between your machine and the Internet

ngrok is a tunneling service that will solve all these problems. It creates a secure tunnel between your local machine and the Internet.

Concretely, ngrok provides you:

  • A free public domain: a unique URL like https://your-url.ngrok-free.app
  • An encrypted tunnel: all traffic between the Internet and your machine goes through a secure tunnel
  • Automatic HTTPS: essential for third-party services to agree to send their webhooks

The diagram is simple:

Test

Here are the steps to follow:

  • Install n8n globally: npm install n8n -g.

  • Run n8n: n8n start (by default on port 5678).

  • Download and install ngrok from ngrok.com, add your authtoken if necessary: ​​ngrok config add-authtoken VOTRE_TOKEN.

  • Expose the port: ngrok http 5678. Ngrok generates a public HTTPS URL accessible everywhere.

But I absolutely do not recommend this method: it is difficult to maintain, pollutes your system and does not manage persistence in isolation. This is where Docker comes into play.

Optimal configuration with Docker

Using Docker means choosing stability. Your n8n instance becomes an isolated, reproducible and easy-to-update environment.

For an n8n container to work properly behind an ngrok tunnel, you need to configure several environment variables and manage data persistence.

Essential environment variables

Here are the critical variables you need to define:

VariesRole
WEBHOOK_URLTells third-party services the exact address where to send webhooks. Must match your ngrok URL.
N8N_EDITOR_BASE_URLSets the public URL to access the n8n interface. Must match your ngrok URL.
N8N_DEFAULT_BINARY_DATA_MODEConfigured to filesystem. Stores large files (PDF, images) on disk rather than in RAM.
N8N_COMMUNITY_PACKAGES_ENABLEDAllows the installation of community nodes (e.g. MCP nodes).

Configuring the .env

Create a .env file at the root of your project folder:

.env
# These variables will be injected into the n8n container
NGROK_TOKEN=your_ngrok_token
NGROK_DOMAIN=your-static-domain.ngrok-free.app
N8N_EDITOR_BASE_URL=https://your-url.ngrok-free.app
WEBHOOK_URL=https://your-url.ngrok-free.app
N8N__COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE=true
N8N_DEFAULT_BINARY_DATA_MODE=filesystem

Data persistence with Docker volumes

Without Docker volume, you lose everything (workflows, identifiers, history) each time the container is restarted.

The principle is simple: we map a local folder on your machine to the n8n data folder in the container.

Test

This mapping ensures that even if the container is deleted or recreated, all your data remains intact on your disk.

Step by step installation

Step 1: Prepare the environment

You need to install two tools:

1. Docker Desktop

Download and install Docker Desktop for your operating system.

Download Docker

Check that Docker is installed:

docker
docker --version

2. ngrok

Download and install ngrok.

Download ngrok

Next, create a free account on ngrok.com and retrieve your authtoken from the dashboard.

Recover your authtoken

Link your machine to your ngrok account:

ngrok
ngrok config add-authtoken VOTRE_TOKEN

Step 2: Enable ngrok tunnel

Open a new terminal and launch the tunnel:

ngrok
ngrok http 5678

ngrok will provide you with a public URL like:

Enable ngrok tunnel

Step 3: Create the Docker Compose file

Create a folder for your project, then add a docker-compose.yml file:

mkdir n8n-local && cd n8n-local

Here is the content of the docker-compose.yml file:

docker-compose.yml
services:
  n8n:
    image: n8nio/n8n:latest
    restart: always
    ports:
      - "5678:5678"
    environment:
      - WEBHOOK_URL=${WEBHOOK_URL}
      - N8N_EDITOR_BASE_URL=${N8N_EDITOR_BASE_URL}
      - N8N_COMMUNITY_PACKAGES_ENABLED=true
      - N8N_DEFAULT_BINARY_DATA_MODE=filesystem
    volumes:
      - ./n8n_data:/home/node/.n8n

  ngrok:
    image: wernight/ngrok
    restart: always
    # Optional command block
    command:
      - "http"
      - "n8n:5678"
      - "--domain=${NGROK_DOMAIN}" # optionnel
    environment:
      - NGROK_AUTHTOKEN=${NGROK_TOKEN}
    depends_on:
      - n8n

Attention: Make sure that the variables NGROK_TOKEN, WEBHOOK_URL, N8N_EDITOR_BASE_URL and NGROK_DOMAIN are well defined in your file .env. For domain, ngrok now offers a free static domain by account.

With this configuration, the ngrok container directly exposes the container n8n. The two communicate in the internal Docker network, this which is more secure and efficient.

Step 4: Launch n8n with Docker

Launch the n8n container:

docker
docker compose up -d

Launch n8n with Docker

Check that the container is rotating:

docker
docker ps

You should see something like this: Check that the container is rotating

With Docker:

  • Docker volumes save your workflows and credentials even after deleting the container.
  • Environment variables are passed directly into docker run, without manual configuration.
  • n8n runs isolated, without polluting your local Node.

Tip: Get a fixed ngrok domain

On ngrok's free plan, the URL changes with each reboot. To avoid changing your docker-compose.yml each time, you can reserve a free static domain on the ngrok dashboard.

Then run ngrok with this domain:

ngrok
ngrok http --domain=your-static-domain.ngrok-free.app 5678

This way, your URL remains always the same, and you no longer need to touch your Docker configuration.

Order Summary

Here is a summary of the essential commands:

# 1. Start the environment (the data directory is created automatically)
docker compose up -d

# 2. Check that everything is running
docker compose ps

# 3. Follow the logs in real time
docker compose logs -f n8n

# 4. Stop the service cleanly
docker compose down

Why move to a server one day?

You're probably wondering: "If it's free and it works, why do some people pay for a server?"

The Docker + ngrok setup on your PC is the best laboratory in the world to get started. But for professional use, the server (VPS) becomes essential for three reasons:

  1. 24/7 availability: Your PC must remain on. If you close your computer to sleep, your automations sleep too. A VPS at €6/month never stops.
  2. Link stability: A Wi-Fi outage at home breaks the tunnel. In the data center, the connection is redundant.
  3. Performance: If you start managing thousands of pieces of data or large files, your PC's resources and the bandwidth limits of ngrok (free plan) will become a bottleneck.

My advice: Start locally to test your ideas, build your first automations at no cost. Once your automations become critical for your business, transfer your file n8n_data to a small VPS.

Conclusion

The alliance of Docker and ngrok allows you to benefit from the advantages of an n8n Cloud subscription, remote accessibility, real-time triggers, complete integrations while maintaining total control over your data and absolute free.

You now have an n8n instance which:

  • 🌐 Can be accessed from anywhere in the world
  • πŸ”’ Has a secure HTTPS connection
  • πŸ“¦ Persist all your data using Docker volumes
  • ⚑ Handles heavy files efficiently
  • πŸ”— Can receive webhooks from any external service

You now have all the cards in hand to transform your PC into a real automation factory. It's up to you! πŸš€