title: How do I solve postgresql error "connection attempt failed"?
body: <p>I wanted to build my springboot project. Then I want to dockerize my code. But when I built, I got error. I think this occured caused by postgresql setting. But I could not find reason. </p>
  
  <p>Could you please help me?</p>
  
  <pre><code>docker-compose.yml file;
  
  version: '2'
  services:
    web:
      build: .
      ports:
        - 8080:8080
    db:
      container_name: productdb
      image: postgres:9.5
      volumes:
      - sample_db:/var/lib/postgresql/data
      environment:
      - POSTGRES_PASSWORD=bright
      - POSTGRES_USER=postgres
      - POSTGRES_DB=productdb
      - PGDATA=/var/lib/postgresql/data/pgdata
      ports:
      - "5432:5432"
  
  volumes:
    productdb: {}
  </code></pre>
  
  <p>application.yml file;</p>
  
  <pre><code>server:
    port: 8761
  eureka:
    client:
    registerWithEureka: false
    fetchRegistry: false
    server:
    enableSelfPreservation: false
    waitTimeInMsWhenSyncEmpty: 0
  
  spring:
    application:
      name: product-service
    datasource:
      url: jdbc:postgresql://db:5432/productdb
      username: postgres
      password: xxxx
      initialization-mode: always
    jpa:
      show-sql: true
      hibernate:
        ddl-auto:
      properties:
        hibernate:
          temp:
            use_jdbc_metadata_defaults: false
  </code></pre>
  
  <p>Error looks like;</p>
  
  <p>org.postgresql.util.PSQLException: The connection attempt failed.</p>
  
  <p>Thank you</p>