Traefik Docker provider and File provider routing priority synchronization
0 reputation · 19 May 2023, 13:16 UTC
0 reputation · 19 May 2023, 13:16 UTC
A repeatable development environment in Traefik is commonly built by decoupling static infrastructure with the file-provider and dynamic services with the Docker provider. The Docker provider discovers containers via labels and hot-reloads routing rules without restarting the proxy.
Routing selection is documented to use the longest path prefix unless an explicit priority is set. When a file-provider rule defines a global fallback that overlaps a Docker-provider label rule, the internal routing table state during rapid start-stop sequences is unclear.
What guarantees deterministic priority resolution between file-provider and Docker-provider rules when both match the same request during container churn? Is there a defined synchronization order for configuration updates from multiple dynamic providers?
31775 reputation · 19 May 2023, 22:51 UTC
Deterministic priority is guaranteed when you assign an explicit numeric priority to each router. If priorities differ, the router with the highest value wins. If priorities are equal, Traefik breaks the tie by load‑order: the router that was loaded (or last updated) last wins. This load‑order is deterministic as long as the static provider list and the sequence of updates do not change.
Traefik merges configurations from all enabled providers into a single routing table. Each router receives a priority value (default 0). When multiple routers match a request, Traefik selects the one with the highest priority; equal priorities are resolved by the router that was processed most recently.
traefik.http.routers..priority.routers..priority.10).traefik.yml), set:
http:
routers:
web:
rule: Host(`example.com`) && PathPrefix(`/`)
priority: 10
traefik.http.routers.web.priority=10
providers section (or load a dynamic file that overrides Docker labels) so the load‑order is fixed.Access the Traefik dashboard (http://<traefik>:8080/dashboard/) and check the Routers list; each router should display the priority number you set. Perform a curl request to the target host/path and confirm the expected service responds. Changing a priority label and observing the response switch confirms the synchronization works.
If the observed behavior does not match the expected priority, please provide the current priority values seen for the conflicting routers from both the Docker container (docker inspect <container> --format '{{ index .Config.Labels "traefik.http.routers.web.priority" }}') and the file‑based router (from the dashboard or static config). This detail determines whether the tie‑break rule is being applied.
Use comments to ask for clarification. Post a solution as an answer.
4,150 reputation · 19 May 2023, 17:38 UTC
One clarification on resolution order: when priorities are set, Traefik compares numeric priority first and only falls back to longest-prefix matching when priorities are equal. The documented "longest path prefix unless an explicit priority is set" means the prefix heuristic is used only as the default priority derivation, not as a secondary tie-breaker after an explicit priority.
Provider updates are merged in a single reconciliation step. A file change or Docker event triggers a full rebuild of the dynamic configuration from all enabled providers, so the resulting routing table is atomic for that reconciliation. The relative order between file-provider and Docker-provider is the registration order in static config, not a fixed file-before-docker guarantee. During rapid start-stop churn the file watcher and Docker event handlers can fire close together, which can briefly expose an intermediate snapshot until the next reconciliation completes.
Verification tip: `traefik config dump` or the admin API shows the effective priority per router after merge, which is useful to confirm cross-provider values are comparable.