Docker swarm: how to place app and db together?











up vote
2
down vote

favorite
1












I have stack with 2 services: Spring boot application and mongo database.
I want to deploy this stack to Docker Swarm (1 node in Germany, 1 in Finland and 1 in Estonia).



Currently Swarm schedules application to Germany cluster and Database to Finland, which means that every request goes from Germany to Finland.



Is this way how to force Swarm place all pieces of stack to single node ?



P.S. sticking to hostname is not a solution, because if node dies service is down.



My Stack.yml is:



version: '3.3'
services:
app:
image: kyberorg/boot-mongo
networks:
- net
ports:
- "8080:8080"
depends_on:
- mongo
labels:
- ee.yadev.bootmongoapp
deploy:
mode: replicated
replicas: 1
update_config:
parallelism: 1
delay: 10s
mongo:
image: mongo
networks:
- net
volumes:
- example-mongo:/data/db
deploy:
mode: replicated
replicas: 1
update_config:
parallelism: 1
delay: 10s
networks:
net:
driver: overlay
volumes:
example-mongo:
external: true









share|improve this question






















  • You can use binpack deployment strategy. Docker will do it's best to deploy all the services to single node
    – WildDev
    Nov 20 at 18:59















up vote
2
down vote

favorite
1












I have stack with 2 services: Spring boot application and mongo database.
I want to deploy this stack to Docker Swarm (1 node in Germany, 1 in Finland and 1 in Estonia).



Currently Swarm schedules application to Germany cluster and Database to Finland, which means that every request goes from Germany to Finland.



Is this way how to force Swarm place all pieces of stack to single node ?



P.S. sticking to hostname is not a solution, because if node dies service is down.



My Stack.yml is:



version: '3.3'
services:
app:
image: kyberorg/boot-mongo
networks:
- net
ports:
- "8080:8080"
depends_on:
- mongo
labels:
- ee.yadev.bootmongoapp
deploy:
mode: replicated
replicas: 1
update_config:
parallelism: 1
delay: 10s
mongo:
image: mongo
networks:
- net
volumes:
- example-mongo:/data/db
deploy:
mode: replicated
replicas: 1
update_config:
parallelism: 1
delay: 10s
networks:
net:
driver: overlay
volumes:
example-mongo:
external: true









share|improve this question






















  • You can use binpack deployment strategy. Docker will do it's best to deploy all the services to single node
    – WildDev
    Nov 20 at 18:59













up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





I have stack with 2 services: Spring boot application and mongo database.
I want to deploy this stack to Docker Swarm (1 node in Germany, 1 in Finland and 1 in Estonia).



Currently Swarm schedules application to Germany cluster and Database to Finland, which means that every request goes from Germany to Finland.



Is this way how to force Swarm place all pieces of stack to single node ?



P.S. sticking to hostname is not a solution, because if node dies service is down.



My Stack.yml is:



version: '3.3'
services:
app:
image: kyberorg/boot-mongo
networks:
- net
ports:
- "8080:8080"
depends_on:
- mongo
labels:
- ee.yadev.bootmongoapp
deploy:
mode: replicated
replicas: 1
update_config:
parallelism: 1
delay: 10s
mongo:
image: mongo
networks:
- net
volumes:
- example-mongo:/data/db
deploy:
mode: replicated
replicas: 1
update_config:
parallelism: 1
delay: 10s
networks:
net:
driver: overlay
volumes:
example-mongo:
external: true









share|improve this question













I have stack with 2 services: Spring boot application and mongo database.
I want to deploy this stack to Docker Swarm (1 node in Germany, 1 in Finland and 1 in Estonia).



Currently Swarm schedules application to Germany cluster and Database to Finland, which means that every request goes from Germany to Finland.



Is this way how to force Swarm place all pieces of stack to single node ?



P.S. sticking to hostname is not a solution, because if node dies service is down.



My Stack.yml is:



version: '3.3'
services:
app:
image: kyberorg/boot-mongo
networks:
- net
ports:
- "8080:8080"
depends_on:
- mongo
labels:
- ee.yadev.bootmongoapp
deploy:
mode: replicated
replicas: 1
update_config:
parallelism: 1
delay: 10s
mongo:
image: mongo
networks:
- net
volumes:
- example-mongo:/data/db
deploy:
mode: replicated
replicas: 1
update_config:
parallelism: 1
delay: 10s
networks:
net:
driver: overlay
volumes:
example-mongo:
external: true






docker docker-swarm docker-swarm-mode






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 8:50









kyberorg

1551515




1551515












  • You can use binpack deployment strategy. Docker will do it's best to deploy all the services to single node
    – WildDev
    Nov 20 at 18:59


















  • You can use binpack deployment strategy. Docker will do it's best to deploy all the services to single node
    – WildDev
    Nov 20 at 18:59
















You can use binpack deployment strategy. Docker will do it's best to deploy all the services to single node
– WildDev
Nov 20 at 18:59




You can use binpack deployment strategy. Docker will do it's best to deploy all the services to single node
– WildDev
Nov 20 at 18:59












3 Answers
3






active

oldest

votes

















up vote
0
down vote













my first idea is to suggest you to use "placement constraints" and "labels":



https://docs.docker.com/engine/swarm/services/#placement-constraints
https://docs.docker.com/engine/swarm/manage-nodes/#add-or-remove-label-metadata



Thanks to them you can assign labels to nodes for each country and then modify your stack in order to force the apps to run on the same node.



docker node update --label-add country=Germany node-germany
docker node update --label-add country=Finland node-finland



--constraint node.labels.region==east



version: '3.3'
services:
app:
image: kyberorg/boot-mongo
deploy:
placement:
constraints:
- country == Germany



mongo:
image: mongo
deploy:
placement:
constraints:
- country == Germany



Other useful links:



https://semaphoreci.com/community/tutorials/scheduling-services-on-a-docker-swarm-mode-cluster
https://container-solutions.com/using-binpack-with-docker-swarm/



I hope this can help you!






share|improve this answer





















  • Thanks for answer. Country labels are not what I'm actually looking for. Because if germal node is down, app is down as well. Binpack strategy is good from me. I attempted to add affinity to ENV vars.But neither affinity.service nor affinity.container succeeded.
    – kyberorg
    Nov 19 at 10:50




















up vote
0
down vote













What you are looking for is something like POD in kubernetes where co-location of containers is possible. AFAIK, this is currently not available on docker.



You can have a look at this repo and see if it is useful: https://github.com/rycus86/podlike



It's an attempt to bring the concept of pods to docker.



edit: On a side note, if the app and db are so tightly coupled, it makes sense that both are part of the same container.






share|improve this answer






























    up vote
    0
    down vote













    The architecture of Swarm is one that you usually want a single swarm in the same region due to the latency of managers. Typically a swarm is "single region, multiple availability zones" (datacenters close to each other, in the same city usually.)



    I also can't think of a way where you can use either constraints and/or placement preferences to have the two containers together in one datacenter, and then managers move them to the same 2nd datacenter if the first is down.



    Podlike, like giabar mentioned, is an option but doesn't solve your "single swarm across multiple regions" design challenge.






    share|improve this answer





















      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',
      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%2f53371100%2fdocker-swarm-how-to-place-app-and-db-together%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      my first idea is to suggest you to use "placement constraints" and "labels":



      https://docs.docker.com/engine/swarm/services/#placement-constraints
      https://docs.docker.com/engine/swarm/manage-nodes/#add-or-remove-label-metadata



      Thanks to them you can assign labels to nodes for each country and then modify your stack in order to force the apps to run on the same node.



      docker node update --label-add country=Germany node-germany
      docker node update --label-add country=Finland node-finland



      --constraint node.labels.region==east



      version: '3.3'
      services:
      app:
      image: kyberorg/boot-mongo
      deploy:
      placement:
      constraints:
      - country == Germany



      mongo:
      image: mongo
      deploy:
      placement:
      constraints:
      - country == Germany



      Other useful links:



      https://semaphoreci.com/community/tutorials/scheduling-services-on-a-docker-swarm-mode-cluster
      https://container-solutions.com/using-binpack-with-docker-swarm/



      I hope this can help you!






      share|improve this answer





















      • Thanks for answer. Country labels are not what I'm actually looking for. Because if germal node is down, app is down as well. Binpack strategy is good from me. I attempted to add affinity to ENV vars.But neither affinity.service nor affinity.container succeeded.
        – kyberorg
        Nov 19 at 10:50

















      up vote
      0
      down vote













      my first idea is to suggest you to use "placement constraints" and "labels":



      https://docs.docker.com/engine/swarm/services/#placement-constraints
      https://docs.docker.com/engine/swarm/manage-nodes/#add-or-remove-label-metadata



      Thanks to them you can assign labels to nodes for each country and then modify your stack in order to force the apps to run on the same node.



      docker node update --label-add country=Germany node-germany
      docker node update --label-add country=Finland node-finland



      --constraint node.labels.region==east



      version: '3.3'
      services:
      app:
      image: kyberorg/boot-mongo
      deploy:
      placement:
      constraints:
      - country == Germany



      mongo:
      image: mongo
      deploy:
      placement:
      constraints:
      - country == Germany



      Other useful links:



      https://semaphoreci.com/community/tutorials/scheduling-services-on-a-docker-swarm-mode-cluster
      https://container-solutions.com/using-binpack-with-docker-swarm/



      I hope this can help you!






      share|improve this answer





















      • Thanks for answer. Country labels are not what I'm actually looking for. Because if germal node is down, app is down as well. Binpack strategy is good from me. I attempted to add affinity to ENV vars.But neither affinity.service nor affinity.container succeeded.
        – kyberorg
        Nov 19 at 10:50















      up vote
      0
      down vote










      up vote
      0
      down vote









      my first idea is to suggest you to use "placement constraints" and "labels":



      https://docs.docker.com/engine/swarm/services/#placement-constraints
      https://docs.docker.com/engine/swarm/manage-nodes/#add-or-remove-label-metadata



      Thanks to them you can assign labels to nodes for each country and then modify your stack in order to force the apps to run on the same node.



      docker node update --label-add country=Germany node-germany
      docker node update --label-add country=Finland node-finland



      --constraint node.labels.region==east



      version: '3.3'
      services:
      app:
      image: kyberorg/boot-mongo
      deploy:
      placement:
      constraints:
      - country == Germany



      mongo:
      image: mongo
      deploy:
      placement:
      constraints:
      - country == Germany



      Other useful links:



      https://semaphoreci.com/community/tutorials/scheduling-services-on-a-docker-swarm-mode-cluster
      https://container-solutions.com/using-binpack-with-docker-swarm/



      I hope this can help you!






      share|improve this answer












      my first idea is to suggest you to use "placement constraints" and "labels":



      https://docs.docker.com/engine/swarm/services/#placement-constraints
      https://docs.docker.com/engine/swarm/manage-nodes/#add-or-remove-label-metadata



      Thanks to them you can assign labels to nodes for each country and then modify your stack in order to force the apps to run on the same node.



      docker node update --label-add country=Germany node-germany
      docker node update --label-add country=Finland node-finland



      --constraint node.labels.region==east



      version: '3.3'
      services:
      app:
      image: kyberorg/boot-mongo
      deploy:
      placement:
      constraints:
      - country == Germany



      mongo:
      image: mongo
      deploy:
      placement:
      constraints:
      - country == Germany



      Other useful links:



      https://semaphoreci.com/community/tutorials/scheduling-services-on-a-docker-swarm-mode-cluster
      https://container-solutions.com/using-binpack-with-docker-swarm/



      I hope this can help you!







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 19 at 9:36









      giabar

      1




      1












      • Thanks for answer. Country labels are not what I'm actually looking for. Because if germal node is down, app is down as well. Binpack strategy is good from me. I attempted to add affinity to ENV vars.But neither affinity.service nor affinity.container succeeded.
        – kyberorg
        Nov 19 at 10:50




















      • Thanks for answer. Country labels are not what I'm actually looking for. Because if germal node is down, app is down as well. Binpack strategy is good from me. I attempted to add affinity to ENV vars.But neither affinity.service nor affinity.container succeeded.
        – kyberorg
        Nov 19 at 10:50


















      Thanks for answer. Country labels are not what I'm actually looking for. Because if germal node is down, app is down as well. Binpack strategy is good from me. I attempted to add affinity to ENV vars.But neither affinity.service nor affinity.container succeeded.
      – kyberorg
      Nov 19 at 10:50






      Thanks for answer. Country labels are not what I'm actually looking for. Because if germal node is down, app is down as well. Binpack strategy is good from me. I attempted to add affinity to ENV vars.But neither affinity.service nor affinity.container succeeded.
      – kyberorg
      Nov 19 at 10:50














      up vote
      0
      down vote













      What you are looking for is something like POD in kubernetes where co-location of containers is possible. AFAIK, this is currently not available on docker.



      You can have a look at this repo and see if it is useful: https://github.com/rycus86/podlike



      It's an attempt to bring the concept of pods to docker.



      edit: On a side note, if the app and db are so tightly coupled, it makes sense that both are part of the same container.






      share|improve this answer



























        up vote
        0
        down vote













        What you are looking for is something like POD in kubernetes where co-location of containers is possible. AFAIK, this is currently not available on docker.



        You can have a look at this repo and see if it is useful: https://github.com/rycus86/podlike



        It's an attempt to bring the concept of pods to docker.



        edit: On a side note, if the app and db are so tightly coupled, it makes sense that both are part of the same container.






        share|improve this answer

























          up vote
          0
          down vote










          up vote
          0
          down vote









          What you are looking for is something like POD in kubernetes where co-location of containers is possible. AFAIK, this is currently not available on docker.



          You can have a look at this repo and see if it is useful: https://github.com/rycus86/podlike



          It's an attempt to bring the concept of pods to docker.



          edit: On a side note, if the app and db are so tightly coupled, it makes sense that both are part of the same container.






          share|improve this answer














          What you are looking for is something like POD in kubernetes where co-location of containers is possible. AFAIK, this is currently not available on docker.



          You can have a look at this repo and see if it is useful: https://github.com/rycus86/podlike



          It's an attempt to bring the concept of pods to docker.



          edit: On a side note, if the app and db are so tightly coupled, it makes sense that both are part of the same container.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 at 18:14

























          answered Nov 20 at 18:08









          vimal-k

          383




          383






















              up vote
              0
              down vote













              The architecture of Swarm is one that you usually want a single swarm in the same region due to the latency of managers. Typically a swarm is "single region, multiple availability zones" (datacenters close to each other, in the same city usually.)



              I also can't think of a way where you can use either constraints and/or placement preferences to have the two containers together in one datacenter, and then managers move them to the same 2nd datacenter if the first is down.



              Podlike, like giabar mentioned, is an option but doesn't solve your "single swarm across multiple regions" design challenge.






              share|improve this answer

























                up vote
                0
                down vote













                The architecture of Swarm is one that you usually want a single swarm in the same region due to the latency of managers. Typically a swarm is "single region, multiple availability zones" (datacenters close to each other, in the same city usually.)



                I also can't think of a way where you can use either constraints and/or placement preferences to have the two containers together in one datacenter, and then managers move them to the same 2nd datacenter if the first is down.



                Podlike, like giabar mentioned, is an option but doesn't solve your "single swarm across multiple regions" design challenge.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  The architecture of Swarm is one that you usually want a single swarm in the same region due to the latency of managers. Typically a swarm is "single region, multiple availability zones" (datacenters close to each other, in the same city usually.)



                  I also can't think of a way where you can use either constraints and/or placement preferences to have the two containers together in one datacenter, and then managers move them to the same 2nd datacenter if the first is down.



                  Podlike, like giabar mentioned, is an option but doesn't solve your "single swarm across multiple regions" design challenge.






                  share|improve this answer












                  The architecture of Swarm is one that you usually want a single swarm in the same region due to the latency of managers. Typically a swarm is "single region, multiple availability zones" (datacenters close to each other, in the same city usually.)



                  I also can't think of a way where you can use either constraints and/or placement preferences to have the two containers together in one datacenter, and then managers move them to the same 2nd datacenter if the first is down.



                  Podlike, like giabar mentioned, is an option but doesn't solve your "single swarm across multiple regions" design challenge.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 20 at 19:02









                  Bret Fisher

                  3,07611321




                  3,07611321






























                      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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2f53371100%2fdocker-swarm-how-to-place-app-and-db-together%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

                      Ottavio Pratesi

                      Tricia Helfer

                      15 giugno