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


























    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
























      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 7 hours ago









      kyberorg

      1551515




      1551515
























          1 Answer
          1






          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








          New contributor




          giabar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • 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
            5 hours ago













          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

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          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








          New contributor




          giabar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • 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
            5 hours ago

















          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








          New contributor




          giabar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • 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
            5 hours ago















          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








          New contributor




          giabar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          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








          New contributor




          giabar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          giabar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered 6 hours ago









          giabar

          1




          1




          New contributor




          giabar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          giabar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          giabar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.












          • 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
            5 hours ago




















          • 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
            5 hours ago


















          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
          5 hours ago






          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
          5 hours ago




















           

          draft saved


          draft discarded



















































           


          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

          '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]