docker compose with swarm and spring boot, cannot connect to database on different node

This is my docker-compose.yml file:

version: '2'
services:
  app:
    image: pedramrn/webapp:0.1.4
    expose:
      - 8080
    networks:
      - main
    working_dir: /src
    restart: never
    depends_on:
      - db-postgresql
    links:
      - db-postgresql

  lb:
    image: dockercloud/haproxy:1.5
    depends_on:
      - app
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - 80:80
    networks:
      - main
    environment:
      - ADDITIONAL_SERVICES=springbootdockertemplate:app


  db-postgresql:
    image: postgres:9.5
    ports:
      - "5432:5432"
    volumes:
      - data-postgresql:/var/lib/postgresql/data
    networks:
      - main
    restart: unless-stopped
    environment:
      - POSTGRES_USER=user
      - POSTGRES_PASSWORD=pass
      - POSTGRES_DB=postgres


volumes:
  data-postgresql:

networks:
  main:

This is the datasource url: jdbc:postgresql://db-postgresql:5432/postgres

  • docker: command not found with Jenkins build and publish plugin on Mac
  • How to run a specific profile on WebSphere on Docker?
  • Docker compose mysql reachable on port 3306
  • Docker build MySQL dockerfile occur none:none
  • Jenkins build inside a docker container with generated reports
  • Which database does docker use?
  • If I remove the links: db-postgresql spring boot cannot connect to postgres database, though it will works without links on a single node but not with each container on a different node.

    on the docker documentation, with the new multi-host networking feature, containers can resolves with their names.

    Note: I have set up the keystore with consul according to documentation.

    Client:                                       
     Version:      1.11.1                         
     API version:  1.23                           
     Go version:   go1.5.4                        
     Git commit:   5604cbe                        
     Built:        Tue Apr 26 23:44:17 2016       
     OS/Arch:      windows/amd64                  
    
    Server:                                       
     Version:      swarm/1.2.3                    
     API version:  1.22                           
     Go version:   go1.5.4                        
     Git commit:   eaa53c7                        
     Built:        Fri May 27 17:25:03 UTC 2016   
     OS/Arch:      linux/amd64   
    
    Dev system: Windows 8.1 X64 
    

  • Build and run a development environment with Docker
  • How i can configure dockerized WildFly with HornetQ?
  • How can I increase gitlab CE lfs file size limitation as to not get 500 server errors?
  • Connect Windows container to Linux container running on same Docker host
  • How to stream the logs in docker python API?
  • Docker swarm and service discovery
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.