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

**URL:** <https://community.traefik.io/t/static-config-in-traefik-yml-vs-docker-compose-yml/18837>\
**Category:** Traefik v2\
**Tags:** file, docker\
**Created:** [June 5, 2023, 3:33am UTC](https://community.traefik.io/t/static-config-in-traefik-yml-vs-docker-compose-yml/18837 "2023-06-05T03:33:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lonix](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/lonix/32/7172_2.png) [@lonix](https://community.traefik.io/u/lonix)\
**Post date:** [June 5, 2023, 3:33am UTC](https://community.traefik.io/t/static-config-in-traefik-yml-vs-docker-compose-yml/18837/1 "2023-06-05T03:33:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bluepuma77](https://community.traefik.io/u/bluepuma77)\
**Post date:** [June 5, 2023, 5:13am UTC](https://community.traefik.io/t/static-config-in-traefik-yml-vs-docker-compose-yml/18837/2 "2023-06-05T05:13:34Z")

</div>

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](https://doc.traefik.io/traefik/reference/dynamic-configuration/file/), [label reference](https://doc.traefik.io/traefik/reference/dynamic-configuration/docker/)).

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

---

<div class="post-metadata">

**Author:** ![lonix](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/lonix/32/7172_2.png) [@lonix](https://community.traefik.io/u/lonix)\
**Post date:** [June 5, 2023, 6:53am UTC](https://community.traefik.io/t/static-config-in-traefik-yml-vs-docker-compose-yml/18837/3 "2023-06-05T06:53:51Z")

</div>

Thanks for your help. 😃

---

<div class="post-metadata">

**Author:** ![lonix](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/lonix/32/7172_2.png) [@lonix](https://community.traefik.io/u/lonix)\
**Post date:** [June 5, 2023, 7:05am UTC](https://community.traefik.io/t/static-config-in-traefik-yml-vs-docker-compose-yml/18837/4 "2023-06-05T07:05:19Z")

</div>

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

- `command` is for static config
- `labels` is for dynamic config

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/b/bd81ebdb578656e76e56ff3cc3eed021d3ba132d.png) [@system](https://community.traefik.io/u/system)\
**Post date:** [June 8, 2023, 7:05am UTC](https://community.traefik.io/t/static-config-in-traefik-yml-vs-docker-compose-yml/18837/5 "2023-06-08T07:05:31Z")

</div>

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