[英]Db knex migrations: KnexTimeoutError inside docker
After running docker-compose up
which spins up two containers where one is an express server(listing) and the other the database(listing-db).在运行docker-compose up
它启动了两个容器,其中一个是快速服务器(列表),另一个是数据库(列表-db)。 Whenever I try to run the knex migrate:latest
command in the express server (running container, after running the docker exec -it "container id"), I get the KnexTimeoutError.每当我尝试在快速服务器中运行knex migrate:latest
命令时(运行容器,在运行 docker exec -it "container id" 之后),我得到 KnexTimeoutError。 while I am able to get into the db(listing-db) container manually, and switch to the postgres user which is the superuser in this instance, I am not sure why connecting from another container (from the express server in this case) is throwing this error.虽然我能够手动进入 db(listing-db) 容器,并切换到 postgres 用户,在这种情况下是超级用户,但我不确定为什么从另一个容器连接(在这种情况下是从 express 服务器)是抛出这个错误。
(docker-compose.yml) (码头工人-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) (knexfile.js)
module.exports = {
client: 'pg',
connection: process.env.LISTING_DB_URI
};
(package.json) (包.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"
}
}
Command run inside the listing container命令在列表容器内运行
yarn run db:migrate:latest
Error错误
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.
Found the issue, typo postgres://root:password@listing-db/db
>>> postgres://root:password@listings-db/db
发现问题,错字postgres://root:password@listing-db/db
>>> postgres://root:password@listings-db/db
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.