Db knex 迁移:docker 内的 KnexTimeoutError

Db knex migrations: KnexTimeoutError inside docker

在 运行ning docker-compose up 之后启动了两个容器,其中一个是快速服务器(列表),另一个是数据库(列表数据库)。每当我尝试 运行 快递服务器中的 knex migrate:latest 命令时(运行ning 容器,在 运行ning docker exec -it "container id" ), 我得到了 KnexTimeoutError。虽然我能够手动进入 db(listing-db) 容器,并切换到 postgres 用户,在这种情况下是超级用户,但我不确定为什么从另一个容器(在这种情况下是从 express 服务器)连接是抛出这个错误。

(docker-compose.yml)

version: "3"
services: 
    listings:
        build: "./listings"
        depends_on: 
            - listings-db
        environment: 
            - LISTING_DB_URI=postgres://root:password@listing-db/db
        volumes: 
            - ./listings:/opt/app

    listings-db:
        environment: 
            - POSTGRES_PASSWORD=password
            - POSTGRES_DB=db
        image: postgres
        ports: 
            - 0.0.0.0:5100:5432

(knexfile.js)

module.exports = {
     client: 'pg',
     connection: process.env.LISTING_DB_URI
};

(package.json)

{
  "name": "listings",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "db:migrate:latest": "knex migrate:latest",
    "db:migrate:rollback": "knex migrate:rollback",
    "watch": "babel-watch -L src/index.js"
  },
  "dependencies": {
    "@babel/core": "^7.10.2",
    "@babel/polyfill": "^7.10.1",
    "@babel/preset-env": "^7.10.2",
    "babel-plugin-module-resolver": "^4.0.0",
    "dayjs": "^1.8.28",
    "dotenv": "^8.2.0",
    "knex": "^0.21.1",
    "objection": "^2.1.6",
    "objection-db-errors": "^1.1.2",
    "pg": "^8.2.1"
  },
  "devDependencies": {
    "babel-watch": "^7.0.0"
  }
}

列表容器内的命令运行

yarn run db:migrate:latest

错误

KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
    at Client_PG.acquireConnection (/opt/app/node_modules/knex/lib/client.js:349:26)
error Command failed with exit code 1.

发现问题,打字错误 postgres://root:password@listing-db/db >>> postgres://root:password@listings-db/db