<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/cloudflare-tunnels-with-docker-compose-free-ngrok-alternative-chygejkfv" -->

---
title: Cloudflare Tunnels with Docker Compose: Free ngrok...
description: A complete Docker Compose stack pairs a cloudflared container with a Node.js webhook consumer to enable free, session-timeout-free local webhook debugging,...
canonical: https://daily.dev/posts/cloudflare-tunnels-with-docker-compose-free-ngrok-alternative-chygejkfv
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Cloudflare Tunnels with Docker Compose: Free ngrok Alternative | daily.dev
og:description: A complete Docker Compose stack pairs a cloudflared container with a Node.js webhook consumer to enable free, session-timeout-free local webhook debugging,...
og:url: https://daily.dev/posts/cloudflare-tunnels-with-docker-compose-free-ngrok-alternative-chygejkfv
og:image: https://api.daily.dev/og/posts/ChYGeJkfV.png
og:image:alt: Cloudflare Tunnels with Docker Compose: Free ngrok Alternative
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Cloudflare Tunnels with Docker Compose: Free ngrok Alternative

**[SitePoint](https://daily.dev/sources/sitepoint)** · 16 min read · 1 upvotes · 0 comments

## Summary

A complete Docker Compose stack pairs a cloudflared container with a Node.js webhook consumer to enable free, session-timeout-free local webhook debugging, positioned as an alternative to ngrok's free-tier limitations. The guide covers building an Express-based webhook receiver with HMAC-SHA256 signature verification (preserving raw request bodies for correct hashing), configuring ephemeral vs. named Cloudflare tunnels, extracting tunnel URLs programmatically, and an automated bash test suite covering valid, invalid, missing signature, and malformed JSON scenarios. It also covers registering tunnel URLs with Stripe, GitHub, and AI agent callbacks, troubleshooting 502 errors and signature mismatches, and security practices like never committing secrets and rotating them regularly.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.sitepoint.com/setting-up-cloudflare-tunnels-docker-compose-persistent-webhook-debugging>

## Questions this post answers

### How do I set up a free alternative to ngrok for testing webhooks locally with Docker?

Run the cloudflare/cloudflared Docker image alongside a webhook consumer container on a shared Docker network, using the command tunnel --no-autoupdate --url http://webhook:3000 to create an ephemeral tunnel with no session timeout while the container runs. This requires no domain, no configuration, and no paid subscription, unlike ngrok's free tier which enforces session timeouts and random subdomains on restart.

_Developers weighing tunnel tools for webhook testing can track setup approaches like this on daily.dev._

### Why is my Express webhook HMAC signature verification failing even though the secret is correct?

The most common cause is that express.json() discards the raw request body by default, so re-serializing the parsed object with JSON.stringify produces different bytes than the original payload due to differing key ordering or whitespace, causing the HMAC hash to mismatch. Fix this by using the verify callback in express.json() to stash the raw buffer before parsing, then compute the HMAC against that raw buffer instead.

_Anyone debugging signature mismatches in webhook code can bookmark fixes like this via daily.dev._

### Why does my cloudflared tunnel return a 502 error when forwarding webhook requests to my local server?

A 502 from cloudflared means it cannot reach the upstream service, most commonly because the --url flag references localhost instead of the Docker Compose service name, such as http://webhook:3000. Both containers must share the same Docker network, and if the webhook service has not finished starting when cloudflared begins forwarding, requests will also return 502 until a proper health check dependency is configured.

_Developers wiring up containerized tunnels can save troubleshooting steps like this on daily.dev._

## Similar posts on daily.dev

- [Self-hosted HTTP tunnels with SSH and nginx](https://daily.dev/posts/self-hosted-http-tunnels-with-ssh-and-nginx-qeu3pqxry) · Lobsters · 1 upvotes · 0 comments
- [My ISP stuck me behind CGNAT, and a free Cloudflare tunnel made my home server reachable again](https://daily.dev/posts/my-isp-stuck-me-behind-cgnat-and-a-free-cloudflare-tunnel-made-my-home-server-reachable-again-k8tt9qe2s) · XDA Developers · 0 upvotes · 0 comments
- [Cloudflare Tunnels — How it works BTS?](https://daily.dev/posts/cloudflare-tunnels-how-it-works-bts--rb3kdcmnd) · Medium · 0 upvotes · 0 comments
- [How to Expose Your Rails Localhost Securely Using Cloudflare Tunnel](https://daily.dev/posts/how-to-expose-your-rails-localhost-securely-using-cloudflare-tunnel-5icndqzje) · RUBYLAND · 0 upvotes · 0 comments
- [My second Cloudflare Tunnel](https://daily.dev/posts/my-second-cloudflare-tunnel-ackpjuxtl) · A Java geek · 3 upvotes · 0 comments

---

Tags: [#nodejs](https://daily.dev/tags/nodejs), [#docker-compose](https://daily.dev/tags/docker-compose)

[View this post on daily.dev](https://daily.dev/posts/cloudflare-tunnels-with-docker-compose-free-ngrok-alternative-chygejkfv)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Cloudflare Tunnels with Docker Compose: Free ngrok Alternative","url":"https://daily.dev/posts/cloudflare-tunnels-with-docker-compose-free-ngrok-alternative-chygejkfv","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/cloudflare-tunnels-with-docker-compose-free-ngrok-alternative-chygejkfv"},"datePublished":"2026-09-19T15:29:30.130Z","dateModified":"2026-09-19T15:29:55.014Z","description":"A complete Docker Compose stack pairs a cloudflared container with a Node.js webhook consumer to enable free, session-timeout-free local webhook debugging,...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5b55b96834385e73bb40fdacbbd011a1?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/5b55b96834385e73bb40fdacbbd011a1?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"SitePoint","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"SitePoint","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/sitepoint","url":"https://daily.dev/sources/sitepoint"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/cloudflare-tunnels-with-docker-compose-free-ngrok-alternative-chygejkfv","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"nodejs,docker-compose","timeRequired":"PT16M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"SitePoint","item":"https://daily.dev/sources/sitepoint"},{"@type":"ListItem","position":3,"name":"Cloudflare Tunnels with Docker Compose: Free ngrok Alternative"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/cloudflare-tunnels-with-docker-compose-free-ngrok-alternative-chygejkfv#faq","mainEntity":[{"@type":"Question","name":"How do I set up a free alternative to ngrok for testing webhooks locally with Docker?","acceptedAnswer":{"@type":"Answer","text":"Run the cloudflare/cloudflared Docker image alongside a webhook consumer container on a shared Docker network, using the command tunnel --no-autoupdate --url http://webhook:3000 to create an ephemeral tunnel with no session timeout while the container runs. This requires no domain, no configuration, and no paid subscription, unlike ngrok's free tier which enforces session timeouts and random subdomains on restart. Developers weighing tunnel tools for webhook testing can track setup approaches like this on daily.dev."}},{"@type":"Question","name":"Why is my Express webhook HMAC signature verification failing even though the secret is correct?","acceptedAnswer":{"@type":"Answer","text":"The most common cause is that express.json() discards the raw request body by default, so re-serializing the parsed object with JSON.stringify produces different bytes than the original payload due to differing key ordering or whitespace, causing the HMAC hash to mismatch. Fix this by using the verify callback in express.json() to stash the raw buffer before parsing, then compute the HMAC against that raw buffer instead. Anyone debugging signature mismatches in webhook code can bookmark fixes like this via daily.dev."}},{"@type":"Question","name":"Why does my cloudflared tunnel return a 502 error when forwarding webhook requests to my local server?","acceptedAnswer":{"@type":"Answer","text":"A 502 from cloudflared means it cannot reach the upstream service, most commonly because the --url flag references localhost instead of the Docker Compose service name, such as http://webhook:3000. Both containers must share the same Docker network, and if the webhook service has not finished starting when cloudflared begins forwarding, requests will also return 502 until a proper health check dependency is configured. Developers wiring up containerized tunnels can save troubleshooting steps like this on daily.dev."}}]}
```

