A Docker Compose container setup for a Cloudflare Tunnel. This setup allows you to securely expose a local service to the internet using Cloudflare's infrastructure.
Cloudflare Tunnel provides a secure way to expose a web server running on your local network to the public internet. This can be particularly useful for development, accessing internal services remotely, or securely publishing a service without opening ports on your router. The container in this project sets up a Cloudflare Tunnel, making it simple to deploy.
- Docker
- Docker Compose
This setup assumes that Cloudflare is the DNS provider for your domain.
Add the missing information for the environment variables in the .env
file:
CLOUDFLARE_TUNNEL_TOKEN=''
CLOUDFLARE_TUNNEL_TOKEN
: This token is provided by Cloudflare when you create a new tunnel. Replace''
with your actual token.
To get the Cloudflare Tunnel token, follow these steps:
- Log in to your Cloudflare Dashboard.
- Navigate to the Zero Trust section or Access section (depending on the Cloudflare interface).
- Select Tunnels from the navigation menu.
- Click on Create a Tunnel.
- Follow the on-screen instructions to name your tunnel and select your desired configuration.
- Once the tunnel is created, Cloudflare will provide a Tunnel Token. Copy this token and paste it into the
.env
file underCLOUDFLARE_TUNNEL_TOKEN
.
Make sure to edit the .env
file and add your specific token:
nano .env
To prevent .env
from being tracked by version control, run the following command:
git update-index --assume-unchanged .env
Modify the hosts
file if needed to define any custom hostname mappings:
nano config/hosts
Add any additional hosts that need to be mapped within the container. To avoid tracking changes to this file, run:
git update-index --assume-unchanged config/hosts
To start the Cloudflare Tunnel container, run:
docker compose up -d
This command will start the container in detached mode.
To stop the running container, use:
docker compose down
To view the logs for the running container, which can help with troubleshooting:
docker logs cloudflare-tunnel
If you want to remove all containers, networks, and associated volumes:
docker compose down --volumes --remove-orphans
This command will also delete any dangling resources associated with the setup.
- Environment Variables: Ensure that
.env
files are not shared or tracked in version control, as they may contain sensitive information such as API tokens or credentials. - Sensitive Files: Always keep sensitive files like
.env
secure and ensure they are not exposed publicly.
This project is licensed under the GNU Lesser General Public License v3.0 (LGPLv3). You are free to use, modify, and distribute this software under the terms specified in the LGPLv3.
See the LICENSE file for more detailed information.
- Cloudflare Tunnel Documentation: Learn more about how Cloudflare Tunnel works and its various use cases.
- Docker Documentation: Official Docker documentation for commands and features used in this setup.