Skip to main content

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

All configuration in one file.
Split configuration across multiple files:
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:
Traefik loads all .yml, .yaml, and .toml files from the directory.

watch

Optional, Default: false Automatically reload when files change:
Docker/Kubernetes Volume Mounts: File system notifications may not work properly with mounted volumes. Use the parent directory instead:

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:
/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

Traefik must have read access.
3

Check Traefik Logs

Look for parsing errors or file watch issues.

Watch Mode Not Working

If using Docker volumes or Kubernetes ConfigMaps, mount the parent directory, not individual files.

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 rules
  • services.yml - Backend services
  • middleware.yml - Reusable middleware
  • tls.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