20

I'm currently trying to get traefik to use multiple routers and services on a single container, which isn't working and i don't know if this is intended at all.

Why?

Specificly i'm using an gitlab omnibus container and wanted to use / access multiple services inside the omnibus container since gitlab is providing not only "the gitlab website" with it.

What did i try?

I simply tried adding another router to my docker compose file via labels

This is what i have:

labels:
  - "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
  - "traefik.http.services.gitlab.loadbalancer.server.port=80"

This is what i want:

labels:
  - "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
  - "traefik.http.services.gitlab.loadbalancer.server.port=80"
  - "traefik.http.routers.registry.rule=Host(`registry.gitlab.example.com`)"
  - "traefik.http.services.registry.loadbalancer.server.port=5000"

This doesn't work since traefik probably getting confused with what to route to which service and i couldn't find a mechanism that tells traefik exactly which router goes to which service in a case like this.

Is this even possible or am i just missing a little bit of traefik magic?

nevotheless
  • 724
  • 1
  • 6
  • 14

1 Answers1

47

I found the solution to my Question.

There's indeed a little bit i missed:

  • traefik.http.routers.myRouter.service=myService

With this Label i can point a Router to a specific Service and should be able to add multiple services to one container:

labels:
  - "traefik.http.routers.gitlab.rule=Host(`gitlab.example.com`)"
  - "traefik.http.routers.gitlab.service=gitlab"
  - "traefik.http.services.gitlab.loadbalancer.server.port=80"
  - "traefik.http.routers.registry.rule=Host(`registry.gitlab.example.com`)"
  - "traefik.http.routers.registry.service=registry"
  - "traefik.http.services.registry.loadbalancer.server.port=5000"

Here each router is pointed to a specific service explicitly which normally happens implicitly.

Mathias Brodala
  • 5,905
  • 13
  • 30
nevotheless
  • 724
  • 1
  • 6
  • 14
  • 2
    Could you elaborate a little more? I'm in the same situation. I struggle to find the link between what you tried in your first message and this one. Could you give me a example for a container running two services just like in your message? Thanks – kinoute Jan 24 '20 at 16:14
  • 1
    @kinoute sure, well you only need to use `traefik.http.routers.myRouter.service=myService` to tie a router to a certain service. If you have Services like `traefik.http.services.myService.loadbalancer.server.port=80` and `traefik.http.services.myApiService.loadbalancer.server.port=3000` Make sure to add 2 routers and 2 router service connections like `traefik.http.routers.myRouter.service=myService` & `traefik.http.routers.myOtherRouter.service=myApiService` – nevotheless Jan 26 '20 at 09:06
  • 1
    That last comment made me realize my mistake. The name of `....myRouter.service=myService` should be the name of the services before `loadbalancer`. So in this: `traefik.http.services.myApiService.loadbalancer.server.port=3000`, the associated `router.service` rule should be equal to `myApiService`; i was puting my container name here... :face_palm: – Bancarel Valentin Oct 15 '22 at 12:40