Error: connect ECONNREFUSED 127.0.0.1:5432

docker-compose.yml
version: "3.8"

services:
  database:
    image: postgres
    container_name: database-ignite
    restart: always
    ports:
      - 5432:5432
    environment:
      - POSTGRES_USER=SYSDBA
      - POSTGRES_PASSWORD=masterkey
      - POSTGRES_DB=rentx
    volumes:
      - pgdata:/data/postgres

  app:
    build: .
    container_name: rentx
    ports:
      - 3333:3333
    volumes:
      - .:/usr/app
    depends_on:
      - database

volumes:
  pgdata:
    driver: local

error:
when I run “docker logs rentx -f” it returns this error

rentalx@1.0.0 start
ts-node-dev --inspect --transpile-only --ignore-watch node_modules --respawn src/server.ts

[INFO] 14:53:59 ts-node-dev ver. 2.0.0 (using ts-node ver. 10.8.1, typescript ver. 4.7.3)
Debugger listening on ws://127.0.0.1:9229/a142edaa-8170-49f8-a9a6-ad9bc74bb543
For help, see: Debugging - Getting Started | Node.js
database is running!
Server is running!
Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1237:16)
[ERROR] 14:54:24 Error: connect ECONNREFUSED 127.0.0.1:5432

How I can fix it ?

Please next time paste your compose files wrapped in a preformated text (</> symbol) block .

Just configure your database connection to dabase:5432 instead of 127.0.0.1:5432 in your app container.

I’m having the exact same problem, did you solve it?

If it’s the exact same problem, did you read and try Metin’s solution?