File Provider
Good Old Configuration Files The File provider lets you define dynamic configuration in YAML or TOML files. It’s perfect for static configurations, shared middleware, reusable TLS options, and supplementing other providers.Why Use File Provider?
✅ Version control friendly - Track configuration in Git✅ Shared resources - Define middleware and TLS options once
✅ Cross-provider compatibility - Reference from Docker, Kubernetes, etc.
✅ Go templating - Generate repetitive configurations dynamically
✅ No external dependencies - Just files on disk
Quick Start
1
Enable File Provider
2
Create Dynamic Configuration
/etc/traefik/dynamic/config.yml
3
Auto-Reload Changes
With
watch: true, Traefik automatically reloads when files change.File vs Directory
Single File Mode
Directory Mode (Recommended)
The
filename and directory options are mutually exclusive. Use directory for better organization.Complete Example
Provider Configuration
filename
Optional Path to a single configuration file:directory
Optional (Recommended) Path to directory containing configuration files:.yml, .yaml, and .toml files from the directory.
watch
Optional, Default: false Automatically reload when files change:Go Templating
Generate repetitive configuration dynamically:Templating only works in dynamic configuration files, not in Traefik’s main static configuration.
Template Functions
Traefik supports Sprig template functions:Cross-Provider Usage
Define shared resources in files and reference from other providers:- File Provider
- Docker
- Kubernetes
/etc/traefik/dynamic/middleware.yml
Common Patterns
Shared Middleware Library
/etc/traefik/dynamic/middleware-library.yml
TLS Configuration
/etc/traefik/dynamic/tls.yml
TCP and UDP Services
/etc/traefik/dynamic/tcp-udp.yml
Docker Compose Integration
docker-compose.yml
Troubleshooting
Configuration Not Loading
1
Check File Syntax
2
Verify File Permissions
3
Check Traefik Logs
Watch Mode Not Working
Template Errors
Ensure you’re using dynamic configuration files, not static:Best Practices
1
Organize by Concern
Split configuration into logical files:
routers.yml- Routing rulesservices.yml- Backend servicesmiddleware.yml- Reusable middlewaretls.yml- TLS configuration
2
Version Control
Keep configuration in Git for history and rollback capability.
3
Use Templates Wisely
Templates are great for repetitive config, but can make debugging harder. Use sparingly.
4
Enable Watch Mode
Use
watch: true in development, consider disabling in production for stability.5
Cross-Provider References
Define common middleware and TLS options in files, reference from Docker/Kubernetes.
Next Steps
Routing Reference
Detailed routing configuration options
Middleware
Available middleware and their configuration