Home:ALL Converter>Docker swarm: how to place app and db together?

Docker swarm: how to place app and db together?

Ask Time:2018-11-19T16:50:12         Author:kyberorg

Json Formatter

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

Author:kyberorg,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53371100/docker-swarm-how-to-place-app-and-db-together
yy