Note: This repository contains the DockFlare Agent, which is designed to work as a worker node in a multi-server setup. It is not a standalone project and requires the main DockFlare application to function.
Lightweight workers that report Docker changes, run cloudflared tunnels, and obey the DockFlare Master.
π Website Β· π Agent Docs Β· π Report a Bug Β· β€οΈ Sponsor
DockFlare 3.0 introduces a distributed control plane: a central DockFlare Master coordinates ingress, while lightweight DockFlare Agents sit next to workloads and keep their Cloudflare tunnels in sync. The agent is a headless Python service that watches Docker events, reacts to commands from the master, and supervises a dedicated cloudflared container.
Deploy agents on any Docker-capable host to extend DockFlare beyond a single server. Each agent maintains its own ingress rules, reports health, and continues serving traffic using the last known configuration even if the master becomes temporarily unavailable.
- Distributed ingress β manage tunnels on remote hosts without exposing raw credentials.
- Real-time visibility β agents stream lifecycle events, periodic status reports, and tunnel metrics back to the master.
- Least privilege β per-agent API keys can be rotated or revoked without affecting the rest of the fleet.
- Resilient execution β cached tunnel state lets agents ride out transient master outages.
π Quick Start: Deploying the Agent
To deploy the agent, create the following two files in the same directory.
1. docker-compose.yml
version: '3.8'
services:
docker-socket-proxy:
image: tecnativa/docker-socket-proxy:v0.4.1
container_name: docker-socket-proxy
restart: unless-stopped
environment:
- DOCKER_HOST=unix:///var/run/docker.sock
- CONTAINERS=1
- EVENTS=1
- NETWORKS=1
- IMAGES=1
- POST=1
- PING=1
- EXEC=1
volumes:
- /var/run/docker.sock:/var/run/docker.sock
networks:
- dockflare-internal
dockflare-agent:
image: alplat/dockflare-agent:latest
container_name: dockflare-agent
restart: unless-stopped
env_file:
- .env
environment:
- DOCKER_HOST=${DOCKER_HOST:-tcp://docker-socket-proxy:2375}
- TZ=${TZ:-UTC}
- LOG_LEVEL=${LOG_LEVEL:-info}
volumes:
- agent_data:/app/data
depends_on:
- docker-socket-proxy
networks:
- cloudflare-net
- dockflare-internal
volumes:
agent_data:
networks:
cloudflare-net:
name: cloudflare-net
external: true
dockflare-internal:
name: dockflare-internal2. .env file
Next, create a .env file in the same directory. This file provides the configuration values for the agent service defined above. Refer to the Configuration section below for more details on each variable.
DOCKFLARE_MASTER_URL=https://dockflare.example.com
DOCKFLARE_API_KEY=agent_api_key_goes_here
DOCKER_HOST=tcp://docker-socket-proxy:2375
AGENT_DISPLAY_NAME=Production Server
# control the docker image used for the managed cloudflared tunnel (accepts repo:tag or repo@sha256:<digest>)
CLOUDFLARED_IMAGE=cloudflare/cloudflared:2025.9.0
LOG_LEVEL=info
TZ=Europe/Zurich
Once both files are in place, run docker-compose up -d to start the agent.
- The proxy limits the Docker API surface the agent can reach; only the variables set to
1are exposed. - Granting
IMAGES=1allows the agent to pull the managedcloudflaredimage. - Provide a persistent volume for
/app/datato ensure agent identity survives restarts. - Ensure the external network (
cloudflare-netby default) exists before starting.
| Component | Responsibility |
|---|---|
| DockFlare Master | Stores desired state, reconciles DNS/Access policies, issues commands via HTTPS. |
| Redis | Provides the backplane for heartbeats, command queues, and shared caches. |
| DockFlare Agent | Runs on the managed host, watches Docker events, manages cloudflared, and reports status. |
| cloudflared | The Cloudflare tunnel process launched and supervised by the agent. |
.
βββ DockFlare-Agent/
β βββ __init__.py
β βββ cloudflare_api.py
β βββ main.py
βββ Dockerfile
βββ docker-compose.yml
βββ env-example
βββ overview.json
βββ requirements.txt
βββ README.md
- Bootstrapping β environment variables are loaded, logging is configured, and cached agent identity/tunnel data are restored from
/app/data. - Registration β the agent authenticates with the master using
DOCKFLARE_API_KEY, receives (or refreshes) its Agent ID, and persists it locally. - Thread fan-out β shared Docker client powers four background workers:
manage_tunnelspolls for commands (start_tunnel,stop_tunnel,update_tunnel_config).periodic_status_reporteremits heartbeats and summaries of labelled containers everyREPORT_INTERVAL_SECONDS.listen_for_docker_eventsstreams container lifecycle events fordockflare.enable=trueworkloads.tunnel_health_monitorverifies the managedcloudflaredcontainer remains healthy.
- Shutdown β
cleanup()stops and removes the managed tunnel container before the agent exits.
DockFlare-Agent/cloudflare_api.py provides the thin wrapper that the agent uses to proxy Cloudflare API calls through the master:
get_account_id(master_url, api_key)β resolves the Cloudflare account the master exposes to agents.generate_ingress_rules(rules)β converts desired ingress records into a tunnel configuration payload.update_tunnel_config(master_url, api_key, tunnel_id, ingress_rules)β pushes ingress updates via the masterβs API.
- DockFlare Master v3.0 or later running with Redis and HTTPS enabled.
- Docker Engine on every host that will run the agent.
- Network reachability from the agent to the master (public HTTPS or a private network/VPN).
- Cloudflare account + API token (managed by the master; agents never handle raw Cloudflare credentials).
The agent is configured using environment variables, typically through the .env file shown in the deployment guide.
| Variable | Required | Description |
|---|---|---|
DOCKFLARE_MASTER_URL |
β | Base URL of the DockFlare Master (https://dockflare.example.com). |
DOCKFLARE_API_KEY |
β | Agent API key generated in the master UI (Agents β Generate Key). |
CLOUDFLARED_IMAGE |
β | Preferred Cloudflared release (cloudflare/cloudflared:2025.9.0) or digest (cloudflare/cloudflared@sha256:...). |
DOCKER_HOST |
β | Address of the Docker socket proxy (tcp://docker-socket-proxy:2375). |
AGENT_DISPLAY_NAME |
β | Human-readable name for the agent (Production Server, NAS Server). Falls back to agent-{8chars} if not set. |
CLOUDFLARED_NETWORK_NAME |
β | Docker network used for the managed tunnel (cloudflare-net by default). |
LOG_LEVEL |
β | Python logging level (INFO by default). |
REPORT_INTERVAL_SECONDS |
β | Cadence for status reports (defaults to 30). |
TZ |
β | Host timezone exposed to the container (UTC by default). |
The agent persists lightweight state inside /app/data:
agent_id.txtβ the master-issued identifier for the node.tunnel_state.jsonβ cached tunnel token, ID, name, and desired state.
Bind-mount a volume to /app/data in production so identity survives container restarts.
- Master API key protects administrative APIs; only expose it when enrolling trusted agents.
- Per-agent API keys are revocableβdelete the key in the master UI to immediately cut off a compromised host.
- Transport security β front the master with HTTPS (or Cloudflare Access) so agent traffic is encrypted end-to-end.
- Redis should reside on a trusted network segment and require authentication when deployed outside a lab environment.
- Docker access is mediated through the bundled socket proxy so the agent can only list containers, stream events, manage networks, and operate its tunnel container.
- Least privilege container β the agent image runs as the
dockflareuser (UID/GID 65532); no root processes remain once start-up is complete.
Recommended practices:
- Store agent keys in a password manager and rotate them regularly.
- Use dedicated Cloudflare tunnels per agent for blast-radius isolation.
- Monitor heartbeat gaps on the masterβs Agents page; prune offline nodes promptly.
| Symptom | Resolution |
|---|---|
Agent stuck in pending |
Verify the API key, ensure the agent can reach the master, and enrol it from the UI. |
| Commands never clear | Confirm Redis connectivity and that host clocks are in sync. |
| DNS or Access policies not updating | Check agent logs (docker logs dockflare-agent) and confirm cloudflared is running. |
| Heartbeat offline | Inspect network path and TLS configuration between agent and master. |
The overview.json sample captures the telemetry an active agent reports back to the master and can be used as a reference when debugging payloads.
- Follow the DockFlare Master Quick Start to prepare the control plane.
- Generate an agent key in the master UI and deploy this container on remote hosts.
- Track upcoming releases from the DockFlare Agent Docker Hub repository.
DockFlare Agent is open-source software licensed under the GPL-3.0 license.