从Docker容器访问主机Postgres

时间:2019-10-21 07:26:27

标签: postgresql docker centos centos7

我有一台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.

1 个答案:

答案 0 :(得分:1)

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

相关问题