How To Set Up n8n Locally with PostgreSQL and Ngrok Using Docker
Test and expose your local n8n instance without deploying to a server
Want to test webhooks locally without paying for hosting or domain name?
This setup lets you run n8n on your machine, connect it to PostgreSQL, and expose it to the internet using Ngrok in just a few steps.
1. Download the Project Files
Download and extract the ZIP file containing the Docker setup.
2. Create an Ngrok Account
A. Sign up at Ngrok
B. Copy your auth token from the dashboard
C. Add your auth token to the docker-compose.yml file:
ngrok:
image: ngrok/ngrok:latest
container_name: ngrok
command: http n8n:5678
environment:
- NGROK_AUTHTOKEN=XXXX
ports:
- "4040:4040"
depends_on:
- n8n
restart: alwaysNgrok provides a free way to expose your local services to the internet.
4. Start the Services
Run the following command:
docker-compose up -dThis starts four services: n8n, n8n-runner, PostgreSQL, and Ngrok.
5. Access Ngrok Dashboard
http://localhost:4040Go to the configuration section and look for a URL like:
URL: https://abc123.ngrok.ioThis is your public URL
6. Configure n8n Webhook URL (Important)
Update the WEBHOOK_URL in your docker-compose.yml:
n8n:
image: docker.n8n.io/n8nio/n8n:${N8N_VERSION}
restart: always
environment:
- ...
- WEBHOOK_URL=https://abc123.ngrok.ioRestart the services to apply changes:
docker-compose up -dThis allows external services such as Telegram or Slack to connect to your local n8n instance.
7. Test webhook
Create a Webhook node in n8n. Your endpoint will look like:
https://abc123.ngrok.io/webhook/your-pathYou can test it using:
Postman
Browser
External service (Stripe, Telegram, etc.)
⚠️ Important Notes
Free Ngrok URLs change every time the service restarts
You need to update WEBHOOK_URL each time the URL changes
For a fixed domain, use a paid Ngrok plan
Conclusion
You now have a working local setup for testing real webhooks. From here, you can start building and validating workflows before moving to production.



