1. There is a java spring web application that connects to postgres. connection string to spring.datasource.url=jdbc:postgresql://postgres:5432/postgres

  2. There is a compose-file, which raises the web application and the base.

 version: "3" services: postgres: networks: - backend image: postgres ports: - "5432:5432" volumes: - db-data:/var/lib/postgresql/data worker1: networks: - backend image: scripter51/worker ports: - "8082:8082" deploy: mode: replicated replicas: 2 placement: constraints: [node.role == worker] networks: backend: volumes: db-data: 

  1. I publish services on cars by team

docker stack deploy --compose-file copm.yml test

Problem: If the database and the web application are on the same machine - everything works, if on different machines, then the application cannot find the database by the service name.

    1 answer 1

    The problem was that swarm init was registered on the host, the base was raised by the manager, and the worker was raised on the virtual machine.