2
  1. 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

  2. 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:
  1. 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.

Trymount
  • 121
  • 4
  • Did you try to specify the network driver? And to create the network external? Did you checked the container IPs in the swarm? – pr177 Dec 24 '17 at 18:12
  • A network driver is an overlay. The network is not external. What do you mean by checking the IP address? – Trymount Dec 24 '17 at 18:44
  • When I try to specify an external network, I get a message that it should be created in advance. – Trymount Dec 24 '17 at 18:47
  • If you specify a external network you have to create it via docker network create -d overlay backend You can do also a docker network inspect (be sure that scope is swarm) – pr177 Dec 25 '17 at 10:22

1 Answers1

0

I was able to solve this problem. I was trying to create a network between the host and the virtual machine using the means of the docker - apparently it does not work.

Trymount
  • 121
  • 4