# How to register 2 services (from 2 providers) in the same load balancer?

**URL:** <https://community.traefik.io/t/how-to-register-2-services-from-2-providers-in-the-same-load-balancer/9576>\
**Category:** Traefik v2\
**Tags:** file, docker\
**Created:** [February 4, 2021, 12:06pm UTC](https://community.traefik.io/t/how-to-register-2-services-from-2-providers-in-the-same-load-balancer/9576 "2021-02-04T12:06:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![oliversalzburg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/oliversalzburg/32/3239_2.png) [@oliversalzburg](https://community.traefik.io/u/oliversalzburg)\
**Post date:** [February 4, 2021, 12:06pm UTC](https://community.traefik.io/t/how-to-register-2-services-from-2-providers-in-the-same-load-balancer/9576/1 "2021-02-04T12:06:16Z")

</div>

I'm using the Docker provider to discover an HTTP service in a container. I'm also running the same container on my Docker host and want to include it in the same load balancer.

To include the local Docker host however, I had to use the File provider.

Thus, I end up with 2 routers that both declare the same rules to be activated. One router will send to `web@file` and the other to `web@docker`. However, it only picks one and if the target in that router is down, the request is failed.

I don't see any way to include both containers under the same load balancer. How is this supposed to be solved?

```auto
# traefik.yml
http:
    routers:
        web:
            rule: Host(`web.localhost`)
            tls: true
            service: web
    services:
        web:
            loadBalancer:
                healthCheck:
                    path: /api/ping
                servers:
                    - url: "http://host.docker.internal:8081"
    
# docker-compose.yml
labels:
    traefik.http.routers.web.rule: Host(`web.localhost`)
    traefik.http.routers.web.service: web
    traefik.http.routers.web.tls: "true"
    traefik.http.services.web.loadBalancer.server.port: 80
    traefik.http.services.web.loadBalancer.healthCheck.path: /api/ping

```

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [February 6, 2021, 6:05pm UTC](https://community.traefik.io/t/how-to-register-2-services-from-2-providers-in-the-same-load-balancer/9576/2 "2021-02-06T18:05:52Z")

</div>

Why are you addressing them the same? Is there any way you can differentiate requests between the two, a specific header ,method , path or query ?

---

<div class="post-metadata">

**Author:** ![toxic0berliner](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/toxic0berliner/32/2716_2.png) [@toxic0berliner](https://community.traefik.io/u/toxic0berliner)\
**Post date:** [February 7, 2021, 1:57am UTC](https://community.traefik.io/t/how-to-register-2-services-from-2-providers-in-the-same-load-balancer/9576/3 "2021-02-07T01:57:30Z")

</div>

I'm not sure to fully understand but if you want loadbalancing I believe you don't need any label on your docker container and you just need to add a second server in your toml file. After all, you need only one router and one service with 2 servers in the loadbalancing.

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [February 8, 2021, 2:25am UTC](https://community.traefik.io/t/how-to-register-2-services-from-2-providers-in-the-same-load-balancer/9576/4 "2021-02-08T02:25:56Z")

</div>

If you had multiple servers for the file provider additional `-url` lines would add them and load balance.  
If you wanted to add more services to the docker provider then scaling that service would add more and likewise load balance.

What you are doing is configuring two different routers with the exact same rule and expecting what? to happen.

---

<div class="post-metadata">

**Author:** ![oliversalzburg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/oliversalzburg/32/3239_2.png) [@oliversalzburg](https://community.traefik.io/u/oliversalzburg)\
**Post date:** [February 18, 2021, 8:28am UTC](https://community.traefik.io/t/how-to-register-2-services-from-2-providers-in-the-same-load-balancer/9576/5 "2021-02-18T08:28:58Z")

</div>

Sorry for replying so late ☹

The reason why I set it up like this is, one of the services is provided by Docker and must be discovered through Docker labels, so the correct IP+Port of the container is used. Otherwise, I have to reconfigure this manually every time I start up my Docker Compose setup.

The other service is the same application, but running on my host, in a debugger. I can access this service through `host.docker.internal` statically from my compose setup.

I want to be able to stop the container and seemlessly take over the requests in the instance that I'm debugging.

I assumed, if you specify the same routing options for two routers, they essentially become the same router and load would be balanced between all services that match the routing rules. I can see that that isn't the case.

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [February 18, 2021, 6:15pm UTC](https://community.traefik.io/t/how-to-register-2-services-from-2-providers-in-the-same-load-balancer/9576/6 "2021-02-18T18:15:42Z")

</div>

Hi @oliversalzburg

I have a couple of ideas, but I want to try them out before pitching them.

---

<div class="post-metadata">

**Author:** ![oliversalzburg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/oliversalzburg/32/3239_2.png) [@oliversalzburg](https://community.traefik.io/u/oliversalzburg)\
**Post date:** [March 4, 2021, 9:11am UTC](https://community.traefik.io/t/how-to-register-2-services-from-2-providers-in-the-same-load-balancer/9576/7 "2021-03-04T09:11:46Z")

</div>

I hate to bother, but if you could share those ideas, I'd really appreciate it. My attempts weren't successful at all.

---

<div class="post-metadata">

**Author:** ![oliversalzburg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/oliversalzburg/32/3239_2.png) [@oliversalzburg](https://community.traefik.io/u/oliversalzburg)\
**Post date:** [March 12, 2021, 9:51am UTC](https://community.traefik.io/t/how-to-register-2-services-from-2-providers-in-the-same-load-balancer/9576/8 "2021-03-12T09:51:33Z")

</div>

@cakiwi I'm gonna try my luck one more time with a ping, then I'll just assume it's not going to work

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [March 12, 2021, 1:31pm UTC](https://community.traefik.io/t/how-to-register-2-services-from-2-providers-in-the-same-load-balancer/9576/9 "2021-03-12T13:31:13Z")

</div>

Hi @oliversalzburg

Really sorry about that.

What you have should work if you add a priority to the router in the file provider that is lower than your docker one. If you set it to 1 it would be considered after ever other rule.

I went into a roue of looking into weighted round robin, but that falls apart quickly when the the container is stopped as the service disappears.

---

<div class="post-metadata">

**Author:** ![oliversalzburg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/oliversalzburg/32/3239_2.png) [@oliversalzburg](https://community.traefik.io/u/oliversalzburg)\
**Post date:** [March 12, 2021, 3:36pm UTC](https://community.traefik.io/t/how-to-register-2-services-from-2-providers-in-the-same-load-balancer/9576/10 "2021-03-12T15:36:56Z")

</div>

Thanks a lot. 🙂 I actually hadn't looked at priorities as an option. I also wasn't able to immediately resolve my issue using them, as my complete setup is more complicated and I'm now seeing (understandable) conflicts with other routers.

I will have to work those out before I can ultimately assess if it works as expected.

---

<div class="post-metadata">

**Author:** ![oliversalzburg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/oliversalzburg/32/3239_2.png) [@oliversalzburg](https://community.traefik.io/u/oliversalzburg)\
**Post date:** [March 24, 2021, 3:44pm UTC](https://community.traefik.io/t/how-to-register-2-services-from-2-providers-in-the-same-load-balancer/9576/11 "2021-03-24T15:44:57Z")

</div>

It works flawlessly right now. Thanks a lot.

I want to add that part of my problems were related to two routers unintenionally sharing paths. The inability to negate rules for a router made fixing this more complicated than anticipated.

---

<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:** [March 27, 2021, 3:45pm UTC](https://community.traefik.io/t/how-to-register-2-services-from-2-providers-in-the-same-load-balancer/9576/12 "2021-03-27T15:45:35Z")

</div>

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