Static config in traefik.yml vs docker-compose.yml

I have:

  • docker-compose.yml
  • traefik.yml static config
  • traefik_dynamic.yml dynamic config (referenced by static config file)

I'm new to traefik, but I've read the docs and understand - more or less - the difference between them.

What I learnt:

  • config in the static file can be specified in the compose file instead, in the command and/or labels dictionaries
  • most tutorials and examples - including on the docs site - dump everything in the compose file
  • dynamic config must be separate, in one or more dynamic config files, so traefik can watch for changes

I initially put all static config in the static config file, then realised it's easier to put it in the compose file instead.

My question: what is the best practice? Is there a reason for using a static config file (instead of the compose file), or is it just personal taste?

Static config goes into traefik.yml or command. Dynamic config in a separate file using provider.file or labels using provider.docker.

Note that static can only be loaded with one method, you can’t use both in parallel.

Having it all in docker-compose.yml makes manual handling a bit easier, because you only need a single file. It’s also easier when using Docker Swarm with multiple nodes, don’t need to distribute additional files. And for tutorials it’s mostly in one file so it’s easier for the reader, just needing to create a single and not multiple files.

Separate files can be considered a bit cleaner, may even be necessary for things that can’t be configured with Docker labels (like loadbalancer.servers.url and custom TLS certs), as labels do not support the full set of options (file reference, label reference).

So it’s up to your personal preference or the setup requirements.

1 Like

Thanks for your help. :smiley:

Ahhh, your post also taught me something else... in a docker-compose.yml:

  • command is for static config
  • labels is for dynamic config
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.