Exposing n8n via Ngrok in Docker: A Complete Guide

A Simple Web Developer & Designer
n8n is a powerful workflow automation tool that allows you to automate tasks and integrate apps seamlessly. Often, you might want to expose your local n8n instance to the internet for testing webhooks or integrations. Ngrok provides a simple and secure way to do this. In this guide, we'll set up n8n in Docker and expose it with Ngrok.
Step 1: Run n8n in Docker
Start by pulling the official n8n Docker image:
docker pull n8nio/n8n
Create and run an n8n container:
docker run -it --name n8n-container -p 5678:5678 n8nio/n8n
-p 5678:5678maps the container port 5678 to your local machine, allowing you to access n8n athttp://localhost:5678.
Step 2: Set Up Ngrok
Ngrok will create a public URL that tunnels traffic to your local n8n instance.
Download Ngrok from ngrok.com.
Authenticate your Ngrok account:
ngrok authtoken <your_auth_token>
- Start a tunnel to the n8n port:
ngrok http 5678
Ngrok will display a public URL like https://abcd1234.ngrok.io. Any requests to this URL are forwarded to your local n8n instance.
Step 3: Configure n8n Webhooks
When you create workflows that use webhooks, update the webhook URLs to use the Ngrok public URL. For example:
https://abcd1234.ngrok.io/webhook/my-workflow
This allows external services to trigger your local n8n workflows as if it were running on a public server.
Step 4: Running n8n with Persistent Data (Optional)
To avoid losing workflows and credentials when the container stops, mount a volume:
docker run -it --name n8n-container -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n
-v ~/.n8n:/home/node/.n8nmaps your local directory to the container, preserving data across restarts.
Step 5: Tips for Using Ngrok with n8n
Use the free Ngrok plan for development and testing.
Avoid using the same Ngrok URL for production workflows; consider a paid plan for stable URLs.
Always verify webhook URLs after restarting the Ngrok tunnel because the public URL changes each time.
Conclusion
By combining Docker, n8n, and Ngrok, you can quickly test and expose automation workflows without deploying a full server. This setup is ideal for development, testing, and demo purposes. Once you're confident, you can move to a production-ready setup using a cloud server or a persistent Docker deployment.
