gpt4 book ai didi

postgresql - 从 docker 容器访问主机 postgres

转载 作者:行者123 更新时间:2023-12-04 19:30:55 26 4
gpt4 key购买 nike

我有一个 CentOS 7 服务器,在其上分别运行 postgres(端口 5432)和 docker。

目前我正在尝试从我的 docker 容器访问 postgres 数据库。但我收到以下错误:

    at Connection.parseE (/usr/app/node_modules/pg/lib/connection.js:604:11)
at Connection.parseMessage (/usr/app/node_modules/pg/lib/connection.js:401:19)
at Socket.<anonymous> (/usr/app/node_modules/pg/lib/connection.js:121:22)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
name: 'error',
length: 161,
severity: 'FATAL',
code: '28000',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'auth.c',
line: '489',
routine: 'ClientAuthentication' }```

I have change pg_hba.conf of my host postgres application that too didn't solve the issue.
Any help will be appreciated.

最佳答案

感谢克莱曼斯的帮助,我得到了解决方案。问题是由于 docker 网络,因为它无法连接到主机。因为默认情况下我的容器在 docker 网桥中运行。我将其更改为遇到解决我的问题的主机。下面是我用来运行我的容器的命令docker run --network=host -d <image name>

关于postgresql - 从 docker 容器访问主机 postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58481602/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com