我正在尝试使用typeorm将postgres数据库连接到nodejs。
我曾尝试在本地使用postgres和nodejs进行连接,结果很正常。但是,当我将postgres和nodejs放入docker容器中时,出现了问题。
(postgres容器中docker inspect
的“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"
}
}
]
谢谢