Why by default creates one router per docker service created?

I wonder why always creates by default one router per container with docker provider. Most of times I would have to re use pre created routers instead of have multiple routers with the same rules... or I'wrong or there are some kind of alternative in order to avoid to create defaults routers per container?

I also have this question. Is it just implied that you should be creating a router per each docker service? I have not seen this addressed in the documentation or the variety of youtube tutorials I've watched.

It is common to have multiple services in a docker-compose, e.g. if you have an array of *arr apps which are sharing bind mounts and networks. I tried testing this theory by naming a router "arr" and enabling my services in traefik one at a time.

services:
  radarr:
    labels:
      - "traefik.http.routers.arr.entrypoints=websecure"
      - "traefik.http.routers.arr.rule=Host(`radarr.mydomain.com`)"

I bring it up, and everything is fine. But when I do the next one:

services:
  sonarr:
    labels:
      - "traefik.http.routers.arr.entrypoints=websecure"
      - "traefik.http.routers.arr.rule=Host(`sonarr.mydomain.com`)"

everything returns 404, including the original service radarr which was working.

I concluded that I must name each router uniquely for its service. But then I end up with a 1:1 routers-to-services ratio, and I don't see any point making the names different from each other or different from my docker-compose yaml, so why even separate them out in traefik? The devs could have combined routers and services and at least simplified a ton of documentation. Or am I missing something?

I think it’s really funny how you complain about the complexity of Traefik. Have you ever thought about the target group and if Traefik may be a tool for multi-billion-dollar corporates with hugh IT departments?

Yet others are complaining that they need yet another feature to be integrated into Traefik :sweat_smile:

It took me half a year to learn it, still learning every day here in the forum.

All you need it the rule and potentially the port (if Dockerfile declares multiple with expose) as labels on a service/container. Limiting entrypoints to websecure looks good, but you have set the redirect on 80 anyway. v3 has a new asDefault setting.

So yes, every service/container needs a router (with its own name) with a rule with a domain or path/prefix.

Have a look at nginx-proxy and it’s acme companion. That’s still my go-to solution for single nodes, plug&play, just env vars, no other config for standard use case needed.

PS: you may get away even without any rule, as a default rule can be declared in static config. AFAIK you can use templating, so it could automatically be "service".example.com.

PPS: it’s actually best practice to also use the traefik.enable=true label to not automatically expose every existing service/container by accident.