I have a web application on java spring that connects to postgres. Сonnection string to the database:
spring.datasource.url=jdbc:postgresql://postgres:5432/postgres
There is a compose-file that raises the web application and the database:
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:
- Public services on the machine of the command
docker stack deploy --compose-file comp.yml test
Problem: If the database and the web application are on the same machine - everything works, if at different - then the application can not find the database by the name of the service.