title: DB connection error Error: connect ECONNREFUSED 127.0.0.1:5432?
body: <p>Running a docker container with postgres and npm produces this error, while running them separetly
  (npm and docker) doesn't. What seems to be the error here?</p>
  
  <p>My docker-compose.yml:</p>
  
  <pre><code>version: "3.5"
  services:
    db:
     image: postgres:12.1
     ports:
      - 5432:5432
     environment:
      - FLYWAY_URL=jdbc:postgresql://db:5432/
      - POSTGRES_USER=myuser
      - POSTGRES_PASSWORD=mypass
      - POSTGRES_DB=mydb
     volumes:
      - ./db/data:/var/lib/postgresql/data
  
    migrate:
      image: boxfuse/flyway
      entrypoint: ["sh", "-c", "/flyway/wait-for.sh db:5432 -- flyway migrate"]
      depends_on:
      - db
      volumes:
      - ./common/migrations/:/flyway/sql:rw
      - ./common/scripts/wait-for.sh:/flyway/wait-for.sh:rw
      environment:
  #    - FLYWAY_LOCATIONS=classpath:/common/migrations/
      - FLYWAY_PASSWORD=mypass
      - FLYWAY_USER=myuser
      - FLYWAY_URL=jdbc:postgresql://db:5432/mydb?user=myuser&amp;amp;password=mypass
      - FLYWAY_CONNECT_RETRIES=30
  
  networks:
    default:
      name: mydb-local
  
  services:
    example-service:
      build: .
      volumes:
        - .:/usr/src/app
        - /usr/src/app/node_modules
      ports:
        - 3000:3000
        - 9229:9229
      command: npm start
  </code></pre>
  
  <p>Thing I have checked: </p>
  
  <p>postgresql.conf &amp; pg_hba.conf accepts connections.</p>
  
  <p>DB credentials are correct.</p>
  
  <p>Db is running</p>