
Expose Your Local Server to the Internet with Cloudflare Tunnel

Most of us have an old laptop with decent specifications just lying around. Instead of letting it collect dust, you can turn it into a powerful hosting machine for your personal projects.
However, the first limitation you’ll encounter when hosting services from your laptop is exposing them to the public internet. This typically requires a static public IP address, which is rarely available with most home internet connections.
Network Tunneling
Network tunneling is a technique used to securely transfer data across different networks. Tunneling tools act as intermediaries that proxy internet traffic to your machine. This allows services running on your local device to be accessed from the internet without needing a public IP address or complex router configuration. There are several tunneling tools available that can help achieve this.
Cloudflared
Cloudflared is a tunneling tool from Cloudflare that allows you to expose services running on your local machine to the internet.
It can proxy multiple protocols, including:
- L7: HTTP, HTTPS
- L4: TCP, UDP

Traffic first reaches Cloudflare’s global network and is then securely tunneled to your machine.
Requirements
Before creating a Cloudflare Tunnel, you need a few things.
Domain
You need a public domain to route internet traffic to your machine.
You can either:
- purchase a domain directly from Cloudflare, or
- transfer an existing domain from another registrar.
Payment Method
Cloudflare provides up to 1000 tunnel connections for free. However, a payment method must be attached to your account. This requirement helps Cloudflare prevent abuse of the service.
Creating Your First Tunnel
Follow these steps to create a tunnel.
- Add your domain to Cloudflare and attach a payment method.
- Navigate to Zero Trust → Networks → Connectors.
- Subscribe to the Connectors plan.
- Click Create Tunnel and select Cloudflared.

- Give your tunnel a name and choose the Docker installation option.

Cloudflare will generate a Docker command containing a tunnel token. Instead of running the command directly, we’ll extract the token and use Docker Compose to manage the container.
Project Structure
Create a folder with the following structure:
1cloudflare2├─ docker-compose.yaml3└─ .env
Docker Compose Configuration
Update your docker-compose.yaml file:
1services:2 cloudflared:3 image: cloudflare/cloudflared:latest4 container_name: cloudflared5 restart: unless-stopped6 environment:7 - TUNNEL_TOKEN=${CLOUDFLARE_TUNNEL_TOKEN}8 command: >9 tunnel --no-autoupdate run10 networks:11 - cloudflare1213networks:14 cloudflare:15 external: true
Environment Variables
Paste the extracted token into the .env file:
1CLOUDFLARE_TUNNEL_TOKEN=xxxxxxxx
Create Docker Network
Create a shared Docker network for services that should be accessible through the tunnel.
1docker network create cloudflare
Start the Tunnel
Start the Cloudflared container:
1docker compose up -d
Once the container starts successfully, your tunnel will be connected to Cloudflare.
Exposing a Service
Next, deploy a service and attach it to the same Docker network.
For example, let’s run an NGINX container.
1services:2 nginx:3 image: nginx:latest4 container_name: nginx5 restart: unless-stopped6 networks:7 - cloudflare89networks:10 cloudflare:11 external: true
Configure Routing
Now create an application route in the Cloudflare dashboard.

After the route is configured, your NGINX container will be publicly accessible from anywhere on the internet.
Resources
- Awesome tunneling tools:
https://github.com/anderspitman/awesome-tunneling - Example Docker setup:
https://github.com/pavanbhaskardev/home-lab/tree/main/cloudflare
