【发布时间】:2021-11-21 19:30:51
【问题描述】:
我正在尝试使用 typeorm 将 postgres db 连接到 nodejs。
我尝试在 localhost 中使用 postgres 和 nodejs 执行此操作,并且效果很好。但是,当我将 postgres 和 nodejs 放入 docker 容器时,我遇到了问题。
(docker inspect 中用于 postgres 容器的“IPAdress”字段为 172.19.0.3)
来自 Nodejs 的错误:
web_1 | error: TypeORM connection error: Error: connect ECONNREFUSED 172.19.0.3:5433
docker-compose.yml
services:
web:
build: .
volumes:
- ./:/app
ports:
- "9001:9001"
links:
- pg_db
pg_db:
image: postgres
ports:
- "5433:5433"
env_file:
- docker.env
ormconfig.json
[
{
"name": "default",
"driver": {
"type": "postgres",
"host": "pg_db",
"port": 5433,
"username": "postgres",
"password": "test",
"database": "testDB"
},
"autoSchemaSync": true,
"entities": [
"src/controller/entity/*.js"
],
"cli": {
"entitiesDir": "src/controller/entity"
}
}
]
谢谢
【问题讨论】:
标签: postgresql typescript docker typeorm