MikroORM 拒绝连接到 docker 容器中的 postgres

MikroORM refuses to connect to postgres in docker container

MikroORM 在 docker 容器中出于某种原因说 MikroORM failed to connect to database postgres on postgresql://postgres:*****@127.0.0.1:5432。目前尚不清楚连接过程中出了什么问题。 以下是一些相关文件:
docker-compose.yml

version: "3.9"

services:
  db:
    image: postgres:13
    volumes:
      - db-data:/var/lib/postgresql/data
    environment: 
      - POSTGRES_DB
      - POSTGRES_PASSWORD
  app:
    build: .
    network_mode: bridge
    volumes:
      - app-data:/app/data
    depends_on:
      - db
    env_file: .env

volumes:
  app-data: {}
  db-data: {}

mikro-orm.config.ts

import { MikroORM } from "@mikro-orm/core";
import { User } from "./entities/user";

export default {
  entities: [User],
  migrations: {
    path: './migrations', // path to the folder with migrations
    pattern: /^[\w-]+\d+\.[tj]s$/, // regex pattern for the migration files
  },
  type: "postgresql",
  host: process.env.POSTGRES_HOST,
  port: 5432,
  dbName: process.env.POSTGRES_DB,
  user: process.env.POSTGRES_USER,
  password: process.env.POSTGRES_PASSWORD,
  debug: true,
} as Parameters<typeof MikroORM.init>[0];

还有我的日志

db_1   | 
db_1   | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1   | 
db_1   | 2021-01-15 00:37:58.161 UTC [1] LOG:  starting PostgreSQL 13.1 (Debian 13.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2021-01-15 00:37:58.162 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2021-01-15 00:37:58.162 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2021-01-15 00:37:58.165 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2021-01-15 00:37:58.172 UTC [27] LOG:  database system was shut down at 2021-01-15 00:37:39 UTC
db_1   | 2021-01-15 00:37:58.181 UTC [1] LOG:  database system is ready to accept connections
app_1  | 
app_1  | > bot@1.0.0 start
app_1  | > tsc && node dist/index.js
app_1  | 
app_1  | [discovery] ORM entity discovery started, using ReflectMetadataProvider
app_1  | [discovery] - processing entity User
app_1  | [discovery] - entity discovery finished, found 1 entities, took 49 ms
app_1  | [info] MikroORM failed to connect to database postgres on postgresql://postgres:*****@127.0.0.1:5432

我能够通过将 link 从一个容器添加到下一个容器来解决此问题。通过添加行

    links:
        - "db:db"

app 容器,我能够连接