【问题标题】:Db knex migrations: KnexTimeoutError inside dockerDb knex 迁移:docker 内的 KnexTimeoutError
【发布时间】:2020-06-06 19:47:49
【问题描述】:

在运行docker-compose up 之后,它启动了两个容器,其中一个是快速服务器(列表),另一个是数据库(列表-db)。每当我尝试在快速服务器中运行knex migrate:latest 命令时(运行容器,运行 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.

【问题讨论】:

    标签: javascript docker docker-compose containers knex.js


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 1970-01-01
      • 2019-08-12
      • 1970-01-01
      • 1970-01-01
      • 2017-03-18
      • 2020-04-18
      相关资源
      最近更新 更多