Search code examples
traefiktraefik-routers

Does naming matters when creating a routing rule?


The basic example for routing in the configuration is

version: "3"
services:
  my-container:
    # ...
    labels:
      - traefik.http.routers.my-container.rule=Host(`example.com`)

my-container is the name of the service and it is mentioned in the rule.

The example for multiple routes is different:

version: "3"
services:
  my-container:
    # ...
    labels:
      - traefik.http.routers.www-router.rule=Host(`example-a.com`)
      - traefik.http.routers.www-router.service=www-service
      - traefik.http.services.www-service.loadbalancer.server.port=8000
      - traefik.http.routers.admin-router.rule=Host(`example-b.com`)
      - traefik.http.routers.admin-router.service=admin-service
      - traefik.http.services.admin-service.loadbalancer.server.port=9000

Here the name of the service is not mentioned and made-up (?) names are used.

Does this mean that what is between routers and rule does not matter?

In other words could I always have (for all my containers) the same name, such as

(in one container)
traefik.http.routers.X.rule=Host(`example.com`)

(in another container)
traefik.http.routers.X.rule=Host(`foo.com`)

Solution

  • You need to use different names for Traefik routers, middlewares and services - otherwise you are overwriting existing ones across Docker services.