-
-
Notifications
You must be signed in to change notification settings - Fork 68
StatePersistence.md
DockFlare maintains an internal state to ensure consistency, manage rules across restarts, and enable powerful features like graceful deletion and UI overrides.
DockFlare uses a JSON file, located at /app/data/state.json by default, to store a complete picture of its managed world. This is the application's "memory."
This state file stores critical information for each managed rule, including:
- Core Rule Definition: The hostname, path, and service target for each ingress rule.
-
Rule Source: A flag indicating if the rule was generated from a
dockercontainer's labels or createdmanually through the Web UI. -
Access Policy Configuration:
- The ID of any associated Cloudflare Access Application created by DockFlare.
- A UI Override Flag, which tells DockFlare if the Access Policy for a rule is being managed by the UI instead of the container's labels. This is the key to making UI-based changes persistent.
- Graceful Deletion Timers: When a labeled container stops, DockFlare records when its grace period expires.
- Associated Docker Information: For rules created from labels, it links the rule back to the specific Docker container ID.
- Cloudflare Zone ID: The specific Cloudflare Zone ID associated with the rule's DNS record.
-
Writing State: DockFlare updates the
state.jsonfile whenever a meaningful change occurs:- A new rule is created (from a container or the UI).
- An Access Policy is modified via the UI.
- A container stops, and its rule is marked for deletion.
- A rule is successfully deleted from Cloudflare after its grace period expires.
-
Reading State (on Startup): When DockFlare starts, a comprehensive reconciliation process begins:
- It loads the
state.jsonfile to understand the last known-good configuration. - It queries the Docker API for all currently running containers and their labels.
- It compares the "desired state" (from running containers) with the "persisted state" (from
state.json). - It adds any new rules from running containers that aren't in its state.
- It verifies that rules in its state still correspond to running containers. If a container is gone, it ensures the rule is scheduled for deletion.
- Crucially, it respects the UI override flag, ensuring that even if a container's labels have changed, the UI-defined Access Policy remains in effect.
- It loads the
In the recommended Docker Compose setup, persistence is handled by a named volume. This is essential for proper operation.
services:
dockflare:
# ... other config ...
volumes:
# Mounts the 'dockflare_data' volume to /app/data inside the container
- dockflare_data:/app/data
volumes:
# Defines the named volume, which Docker manages and preserves
dockflare_data:
name: dockflare_dataWithout a persistent volume, the state.json file will be ephemeral and lost every time the container is recreated. This is not recommended, as DockFlare would lose track of deletion timers, manual rules, and all UI overrides.
If you encounter persistent issues or want a completely fresh start, you might need to reset the state.
- Stop the DockFlare container (
docker compose down). - Remove the persistent volume (
docker volume rm dockflare_data). Warning: This permanently deletesstate.jsonand all manual rules and UI overrides. - Restart the DockFlare container (
docker compose up -d).
DockFlare will then start with a clean slate and rebuild its state based entirely on the currently running, labeled containers.