如何从Docker容器解析服务器连接到主机Postgresql DB?

如何从Docker容器解析服务器连接到主机Postgresql DB?,postgresql,docker,Postgresql,Docker,我已经用docker安装了parse server的一个实例。我的数据库在主机上,但当我运行docker时,它会在连接到数据库时显示错误。 docker run -t -d --name parse-server parseplatform/parse-server --appName appname --appId appid--masterKey masterkey --clientKey clientkey --databaseURI postgres://example:1234563@

我已经用docker安装了parse server的一个实例。我的数据库在主机上,但当我运行docker时,它会在连接到数据库时显示
错误。

docker run -t -d --name parse-server parseplatform/parse-server --appName appname --appId appid--masterKey masterkey --clientKey clientkey --databaseURI postgres://example:1234563@localhost/parse-server --serverURL http://sync.example.com:1337/parse --verbose --publicServerURL http://sync.example.com
我得到了这个错误:

Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 5432
}
我尝试使用
--网络主机
,但解析服务器使用此docker给了我
{“错误”:“未经授权”}

我还尝试使用
-o5432:5432
,但它说使用了端口,因为实例在主机上运行


如何从docker parse server连接到主机上的PostgreSQL,而不使用
--network host

问题在于127.0.0.1不是您的主机本地主机地址,而是docker localhost的地址

所以,您有不同的选择,但最好尝试将解析服务器连接到与docker network连接的主机地址:
172.17.0.X

在主机中执行
ifconfig
,查看docker network的IP地址,然后尝试将其放入命令中:

docker run -t -d --name parse-server parseplatform/parse-server --appName appname --appId appid--masterKey masterkey --clientKey clientkey --databaseURI postgres://example:1234563@YOUR_HOST_IP_IN_DOCKER_INTERFACE/parse-server --serverURL http://sync.example.com:1337/parse --verbose --publicServerURL http://sync.example.com

您可以查看无法连接的

。在pg#U hba上“host Docker access to DB”host all 172.17.0.1/16 scram-sha-256发现使用--网络主机仍然可以连接到DB,反向代理将帮助我到达外部,谢谢。