1
我想使用typeorm將postgres數據庫連接到nodejs。從typeorm碼頭集裝箱連接postgres
我試着在localhost中同時使用postgres和nodejs,它工作正常。不過,當我將postgres和nodejs放入泊塢窗容器時,我遇到了問題。
(在docker inspect
爲postgres的容器中的 「IPAdress」 字段是172.19.0.3)從的NodeJS
錯誤:
web_1 | error: TypeORM connection error: Error: connect ECONNREFUSED 172.19.0.3:5433
搬運工-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"
}
}
]
謝謝
哇,我是個白癡。謝謝修復它。 我故意使它成爲5433,因爲postgres的localhost實例使用的是端口5432,但由於某種原因,我認爲docker容器postgres會自動使用5433。 –