high availability database ( postgresql ) with docker swarm

i am new to docker, and just learning docker for quite sometimes,for i am working with LAPP ( Linux, Apache, PHP and PostreSQL ) stack and always working with monolithic architecture where all the things are put together into one single server / vps.

after i learn about docker my mind changes quite a bit, and now i am going to try how to containerized the stack. When i came into the db, i thought if i implemented docker in swarm mode, the db can replicated or sync automatically in my worker node when i scale it up.. but in fact it does not. And here is my .yml file i am using to re-produce the scenario.

version: "3"
services:
  db:
    image: postgres:9.5
    container_name: db
    restart: always
    tty: true
    ports:
      - "5432:5432"
    environment:
      POSTGRES_PASSWORD: mydocker_pass
      POSTGRES_USER: mydocker_user
      POSTGRES_DB: mydocker
    volumes:
      - db-data:/var/lib/postgresql/data
volumes:
  db-data:

at the first time i just create a single container inside my swarm-manager but then i scale up this service with this command docker service scale db_stack_db=2 it works perfectly, now new container are running in my worker node. In my worker node i also have the same volume which i already have in my manager node but sadly when i write something into the db in the manager node, it doesn’t show up in my worker node and vice versa though they have the same volume name, and pre-created database : mydocker and also have the same db user : mydocker_user and db_password mydocker_password which means instance in worker node are not syncing with manager node.

then if anyone here is experienced this kind of scenario, please help me and please kindly share your thoughts with me, what is the best practice with swarm mode? do i only have to put one node for db, because if i scale the db up and if it running in the worker node is it useful and helping the load of the db service? since it doesn’t have same data between manager and worker node.

regards.

Source: StackOverflow