Load balancer for multiple site in different port without host in docker with traefik












1















Suppose I have two web service say they are w1 and w2 which are deployed by docker-compose.



Now I want to create multiple container for each of them, and create a load balancer in front of them which can make the services accessed by this:



http://localhost:8880 //for service w1

http://localhost:8888 //for service w2


I have searched, and I got dockercloud-haproxy and nginx-proxy.



However, the former is deprecated, and the later have to be used with hostname to distinguish different service.



It is kind of complicated for set different hosts especially in development environment.



Then I found traefik. Seems like more configurable. This is the config file I used:



version: "3"
services:
w1:
image: jwilder/whoami
labels:
- "traefik.backend=whoami"
- "traefik.protocol=http"
- "traefik.port=8080"
- "traefik.frontend.entryPoints=http_8080"

w2:
build: . # a simple node server which use port 80
labels:
- "traefik.backend=node"
- "traefik.protocol=http"
- "traefik.port=80"
- "traefik.frontend.entryPoints=http_80"

lb:
image: traefik
command: "--docker
--logLevel=DEBUG
--entryPoints='Name:http_80 Address::80'
--entryPoints='Name:http_8080 Address::8080'"
ports:
- 8880:80
- 8888:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock


While it still can not meet my requirement.



Is this possible or any other alternative solution?










share|improve this question



























    1















    Suppose I have two web service say they are w1 and w2 which are deployed by docker-compose.



    Now I want to create multiple container for each of them, and create a load balancer in front of them which can make the services accessed by this:



    http://localhost:8880 //for service w1

    http://localhost:8888 //for service w2


    I have searched, and I got dockercloud-haproxy and nginx-proxy.



    However, the former is deprecated, and the later have to be used with hostname to distinguish different service.



    It is kind of complicated for set different hosts especially in development environment.



    Then I found traefik. Seems like more configurable. This is the config file I used:



    version: "3"
    services:
    w1:
    image: jwilder/whoami
    labels:
    - "traefik.backend=whoami"
    - "traefik.protocol=http"
    - "traefik.port=8080"
    - "traefik.frontend.entryPoints=http_8080"

    w2:
    build: . # a simple node server which use port 80
    labels:
    - "traefik.backend=node"
    - "traefik.protocol=http"
    - "traefik.port=80"
    - "traefik.frontend.entryPoints=http_80"

    lb:
    image: traefik
    command: "--docker
    --logLevel=DEBUG
    --entryPoints='Name:http_80 Address::80'
    --entryPoints='Name:http_8080 Address::8080'"
    ports:
    - 8880:80
    - 8888:8080
    volumes:
    - /var/run/docker.sock:/var/run/docker.sock


    While it still can not meet my requirement.



    Is this possible or any other alternative solution?










    share|improve this question

























      1












      1








      1








      Suppose I have two web service say they are w1 and w2 which are deployed by docker-compose.



      Now I want to create multiple container for each of them, and create a load balancer in front of them which can make the services accessed by this:



      http://localhost:8880 //for service w1

      http://localhost:8888 //for service w2


      I have searched, and I got dockercloud-haproxy and nginx-proxy.



      However, the former is deprecated, and the later have to be used with hostname to distinguish different service.



      It is kind of complicated for set different hosts especially in development environment.



      Then I found traefik. Seems like more configurable. This is the config file I used:



      version: "3"
      services:
      w1:
      image: jwilder/whoami
      labels:
      - "traefik.backend=whoami"
      - "traefik.protocol=http"
      - "traefik.port=8080"
      - "traefik.frontend.entryPoints=http_8080"

      w2:
      build: . # a simple node server which use port 80
      labels:
      - "traefik.backend=node"
      - "traefik.protocol=http"
      - "traefik.port=80"
      - "traefik.frontend.entryPoints=http_80"

      lb:
      image: traefik
      command: "--docker
      --logLevel=DEBUG
      --entryPoints='Name:http_80 Address::80'
      --entryPoints='Name:http_8080 Address::8080'"
      ports:
      - 8880:80
      - 8888:8080
      volumes:
      - /var/run/docker.sock:/var/run/docker.sock


      While it still can not meet my requirement.



      Is this possible or any other alternative solution?










      share|improve this question














      Suppose I have two web service say they are w1 and w2 which are deployed by docker-compose.



      Now I want to create multiple container for each of them, and create a load balancer in front of them which can make the services accessed by this:



      http://localhost:8880 //for service w1

      http://localhost:8888 //for service w2


      I have searched, and I got dockercloud-haproxy and nginx-proxy.



      However, the former is deprecated, and the later have to be used with hostname to distinguish different service.



      It is kind of complicated for set different hosts especially in development environment.



      Then I found traefik. Seems like more configurable. This is the config file I used:



      version: "3"
      services:
      w1:
      image: jwilder/whoami
      labels:
      - "traefik.backend=whoami"
      - "traefik.protocol=http"
      - "traefik.port=8080"
      - "traefik.frontend.entryPoints=http_8080"

      w2:
      build: . # a simple node server which use port 80
      labels:
      - "traefik.backend=node"
      - "traefik.protocol=http"
      - "traefik.port=80"
      - "traefik.frontend.entryPoints=http_80"

      lb:
      image: traefik
      command: "--docker
      --logLevel=DEBUG
      --entryPoints='Name:http_80 Address::80'
      --entryPoints='Name:http_8080 Address::8080'"
      ports:
      - 8880:80
      - 8888:8080
      volumes:
      - /var/run/docker.sock:/var/run/docker.sock


      While it still can not meet my requirement.



      Is this possible or any other alternative solution?







      docker docker-compose traefik






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 12:51









      hguserhguser

      12.5k39127236




      12.5k39127236
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You need to add the matcher -"traefik.frontend.rule=PathPrefixStrip:/" under w1 and w2. Otherwise it defaults to Host:w1.project_name.



          Also, I believe jwilder/whoami uses the port 8000 instead of 8080, so change - "traefik.port=8080" to - "traefik.port=8000"






          share|improve this answer


























          • Thanks, I will have a try.

            – hguser
            Jan 2 at 13:50











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54006729%2fload-balancer-for-multiple-site-in-different-port-without-host-in-docker-with-tr%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You need to add the matcher -"traefik.frontend.rule=PathPrefixStrip:/" under w1 and w2. Otherwise it defaults to Host:w1.project_name.



          Also, I believe jwilder/whoami uses the port 8000 instead of 8080, so change - "traefik.port=8080" to - "traefik.port=8000"






          share|improve this answer


























          • Thanks, I will have a try.

            – hguser
            Jan 2 at 13:50
















          0














          You need to add the matcher -"traefik.frontend.rule=PathPrefixStrip:/" under w1 and w2. Otherwise it defaults to Host:w1.project_name.



          Also, I believe jwilder/whoami uses the port 8000 instead of 8080, so change - "traefik.port=8080" to - "traefik.port=8000"






          share|improve this answer


























          • Thanks, I will have a try.

            – hguser
            Jan 2 at 13:50














          0












          0








          0







          You need to add the matcher -"traefik.frontend.rule=PathPrefixStrip:/" under w1 and w2. Otherwise it defaults to Host:w1.project_name.



          Also, I believe jwilder/whoami uses the port 8000 instead of 8080, so change - "traefik.port=8080" to - "traefik.port=8000"






          share|improve this answer















          You need to add the matcher -"traefik.frontend.rule=PathPrefixStrip:/" under w1 and w2. Otherwise it defaults to Host:w1.project_name.



          Also, I believe jwilder/whoami uses the port 8000 instead of 8080, so change - "traefik.port=8080" to - "traefik.port=8000"







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 2 at 13:51

























          answered Jan 2 at 13:38









          SiyuSiyu

          3,10911231




          3,10911231













          • Thanks, I will have a try.

            – hguser
            Jan 2 at 13:50



















          • Thanks, I will have a try.

            – hguser
            Jan 2 at 13:50

















          Thanks, I will have a try.

          – hguser
          Jan 2 at 13:50





          Thanks, I will have a try.

          – hguser
          Jan 2 at 13:50




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54006729%2fload-balancer-for-multiple-site-in-different-port-without-host-in-docker-with-tr%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]