title: Problem connecting to postgresql hosted in docker
body: <p>I have below error connecting to postgresql database hosted in docker.</p>
  
  <pre><code>myapp_Container | WARNING - ConnectionBus: Database connections: 0 active, 0 idle.
  myapp_Container | ERROR - ConnectionBus: Opening JDBC connection to Some(db:54325) failed with SQLState: 08001 Error code: 0 Message: The connection attempt failed., giving up...(4/4)
  myapp_Container | WARNING - ConnectionBus: Cannot create database connection.
  </code></pre>
  
  <p>I have two docker-compose files as below </p>
  
  <p>APP Docker-Compose file</p>
  
  <pre><code>version: "3"
  services:
    app:
      image: myapp
      container_name: myapp_Container
      ports:
        - "8081:8081"
      network_mode: postgres_net
      environment:
        - ADMIN_PASSWORD=Password1!
        - DATABASE_ENDPOINT=postgres://user:passwd@db:54325/mydb
      external_links:
        - db:localpostgres_1
  </code></pre>
  
  <p>DB Docker-Compose file</p>
  
  <pre><code>version: "3"
  
  services:
    postgres:
      image: postgres
      container_name: localpostgres_1
      restart: always
      environment:
        - POSTGRES_USER=user
        - POSTGRES_PASSWORD=passwd
        - TZ=Europe/Amsterdam
      ports:
        - 54325:5432
      networks:
        - postgres_net
  
  networks:
    postgres_net:
      external: true
  
  </code></pre>
  
  <p>I created postgres_net via <code>docker network create -d bridge postgres_net</code></p>
  
  <p>Why am I doing this? I want to create apps with same docker-compose structure without creating a postgresql db for each, if I put them together like below it will work.</p>
  
  <pre><code>version: "3"
  services:
    app:
      image: myapp
      container_name: myapp_Container
      ports:
        - "8081:8081"
      environment:
        - ADMIN_PASSWORD=Password1!
        - DATABASE_ENDPOINT=postgres://user:passwd@db/mydb
      links:
        - db
  
    db:
      image: postgres
      container_name: postgres_x
      ports:
        - "54320:5432"
      environment:
        - TZ=Europe/Amsterdam
        - POSTGRES_USER=user
        - POSTGRES_PASSWORD=passwd
      restart: always
  
  </code></pre>
  
  <p>I can connect to the Db via pgadmin, but can't understand why myapp cannot connect, please help</p>
  
  <p>pg_hba.conf</p>
  
  <pre><code>
  local   all             all                                     trust
  # IPv4 local connections:
  host    all             all             127.0.0.1/32            trust
  # IPv6 local connections:
  host    all             all             ::1/128                 trust
  # Allow replication connections from localhost, by a user with the
  # replication privilege.
  local   replication     all                                     trust
  host    replication     all             127.0.0.1/32            trust  
  
  host    replication     all             ::1/128                 trust
  
  host all all all md5
  
  </code></pre>