-
-
Couldn't load subscription status.
- Fork 68
ExternalcloudflaredMode.md
Caution
FOR ADVANCED USERS ONLY
This mode is powerful but requires a solid understanding of Docker networking and existing Cloudflare Tunnel configurations. Misconfiguration can easily lead to services being unreachable. The default Internal Mode is recommended for most users.
DockFlare can integrate with an existing, independently managed cloudflared agent instead of managing its own. This is known as "External Mode."
- You already have a
cloudflaredservice running (e.g., as a systemd service or a separate Docker container). - You want multiple applications or controllers (including DockFlare) to add ingress rules to the same Cloudflare Tunnel.
- You require specific
cloudflaredcommand-line arguments not exposed by DockFlare's internal management.
In External Mode, the responsibilities are divided:
-
You are responsible for:
- Creating a Cloudflare Tunnel resource on the dashboard.
- Running the
cloudflaredagent process and ensuring it remains connected to Cloudflare. -
Crucially, ensuring network connectivity between your
cloudflaredagent and the services DockFlare will point to it. If your services are Docker containers, your external agent must be on a shared Docker network with them to resolve their container names.
-
DockFlare is responsible for:
- Monitoring Docker container labels.
- Creating and deleting CNAME DNS records that point to your external tunnel.
- Updating the ingress rules within your existing tunnel's configuration via the Cloudflare API.
- Creating and managing Cloudflare Access Applications for those rules.
DockFlare DOES NOT start, stop, or manage the cloudflared agent process itself. It only manages the DNS and Tunnel Configuration on Cloudflare's side.
To enable External Mode, set the following environment variables:
-
USE_EXTERNAL_CLOUDFLARED=true: This flag activates the mode. -
EXTERNAL_TUNNEL_ID: The unique ID (UUID) of your existing Cloudflare Tunnel.
Example .env snippet:
# Enable External Mode
USE_EXTERNAL_CLOUDFLARED=true
# Provide the ID of your existing tunnel
EXTERNAL_TUNNEL_ID=6ff42ae2-765d-4adf-befc-ca51f8e4e688 # <-- Replace with your actual Tunnel ID
# TUNNEL_NAME is IGNORED in this mode
# You still need your Cloudflare credentials!
CF_API_TOKEN=your_cloudflare_api_token_here
CF_ACCOUNT_ID=your_cloudflare_account_id_here
CF_ZONE_ID=your_cloudflare_zone_id_hereIf you don't know the ID of your existing tunnel:
- Log in to the Cloudflare Zero Trust Dashboard.
- Navigate to Access -> Tunnels.
- Find your desired tunnel in the list and click on its name.
- The Tunnel ID (a UUID) is displayed on the tunnel's overview page.
-
Network, Network, Network! The most common failure point in this mode is networking. Your external
cloudflaredagent must be able to resolve and reach the service addresses you define in DockFlare's labels (e.g.,http://my-app:80). -
API Permissions: The Cloudflare API Token used by DockFlare still needs
Account:Cloudflare Tunnel:EditandZone:DNS:Editpermissions to modify the external tunnel's configuration and manage DNS. - Authoritative Management: DockFlare assumes it has authoritative control over the ingress rules and associated DNS records for the hostnames it manages. It may remove rules or DNS records from the tunnel that it doesn't recognize from its own state. Do not have other systems managing ingress rules for the same hostnames on the same tunnel.
You should be able to answer "Yes" to all these questions before proceeding:
- Do I have a
cloudflaredagent already running and connected to my tunnel, completely separate from DockFlare?- Does my
cloudflaredagent have network access to the Docker services I want to expose?- Am I comfortable troubleshooting Docker networking issues independently?
- Do I understand that DockFlare will be modifying the DNS and Ingress Rules of my existing tunnel?