![](/img/trans.png)
[英]How to access postgres database on host from within docker container?
[英]Access host postgres from docker container
我有一個 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>
的命令
當您的主機操作系統是 centOS 7 時,默認情況下您已經運行了防火牆。 您需要啟用對 postgresql 服務器的外部訪問,因為如果未配置 postgres 端口,防火牆將阻止連接。
您可以按照這些說明設置防火牆
https://serverfault.com/questions/789014/issues-configuring-firewall-rules-for-postgres-on-centos
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.