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

  • Building a compiled application with Docker
  • How to get docker to work within vagrant?
  • Strange Vagrant error with Docker and shell provisioners
  • Issues with proxy in Gitlab CI using Docker runner
  • Docker Bash Has No Colour
  • docker COPY with file globbing
  • 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 
    

  • Network communication between Docker images
  • Update docker image resulting in orphan image
  • How to update Kafka config file with Docker IP address
  • Run selenium tests in docker container
  • level=fatal msg=“ipset [destroy] failed: ipset v6.29: Set cannot be destroyed: it is in use by a kernel component\n: exit status 1”
  • can't pull docker images from nexus proxy
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.