简体   繁体   English

与 127.0.0.1:5432 的连接被拒绝。 检查主机名和端口是否正确以及 postmaster 是否接受 TCP/IP 连接

[英]Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections

I'm running my code from docker-compose which is trying to access a local database(postgres).我正在尝试访问本地数据库(postgres)的 docker-compose 运行我的代码。 whenever i try to run i get this error每当我尝试运行时,我都会收到此错误

Connection to 127.0.0.1:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

but postgres is running on port 5432但是 postgres 在端口5432上运行

here is ther result of sudo netstat -ltnp | grep postgres这是sudo netstat -ltnp | grep postgres的结果sudo netstat -ltnp | grep postgres

tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      1995/postgres

I'am using postgres v 10.9 on ubunto OS.我在 ubunto 操作系统上使用 postgres v 10.9。

If you try to access to localhost inside a container then it's the localhost of the container not your machine or any other container.如果您尝试访问容器内的本地主机,那么它是容器的本地主机,而不是您的机器或任何其他容器。 If both your app and database are declare in the same compose, use the same network you can use the container name如果您的应用程序和数据库都在同一个组合中声明,请使用相同的网络,您可以使用容器名称

That is correct, but if you have Postgres installed in you local machine, you could bypass the container restriction setting your machine's IP, eg connecting to Postgres to:5432这是正确的,但如果你在本地机器上安装了 Postgres,你可以绕过容器限制设置你机器的 IP,例如连接到 Postgres 到:5432

If still not working, check if you have any firewall restriction on your local machine, on port 5432 and check if Postgres is set to recive data from external source.如果仍然无法正常工作,请检查本地计算机上的 5432 端口是否有任何防火墙限制,并检查 Postgres 是否设置为从外部源接收数据。

Plus this example should be only used "at home", I do not suggest to use it in company network or any production environment.加上这个例子应该只在“家里”使用,我不建议在公司网络或任何生产环境中使用它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检查主机名和端口是否正确以及 postmaster 是否接受 TCP/IP 连接 - Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections 连接到<hostname> :5432 拒绝 - Connection to <hostname>:5432 refused 来电 <hostname> / <ip> 至 <hostname> :9000连接异常失败:java.net.ConnectException:连接被拒绝 - Call From <hostname>/<ip> to <hostname>:9000 failed on connection exception: java.net.ConnectException: Connection refused Cassandra无法在OSX上启动“原因:连接被拒绝”。 - Cassandra won't start on OSX “Reason: Connection refused.” IOException java.net.ConnectException:无法连接到/127.0.0.1(port 5000):connect failed:ECONNREFUSED(Connection Refused) - IOException java.net.ConnectException: failed to connect to /127.0.0.1(port 5000):connect failed:ECONNREFUSED(Connection Refused) java.net.ConnectException:无法连接到 localhost/127.0.0.1(端口 80):连接失败:ECONNREFUSED(连接被拒绝) - java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 80): connect failed: ECONNREFUSED (Connection refused) 与主机 localhost、端口 1433 的 TCP/IP 连接失败 - The TCP/IP connection to the host localhost, port 1433 has failed 如何检查客户端是否连接到TCP / IP端口 - how to check whether a client is connected to a tcp/ip port 错误:与主机的TCP / IP连接失败。 java.net.ConnectException:连接被拒绝:连接 - Error:The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect RMI ConnectException:连接拒绝托管:127.0.0.1 - RMI ConnectException: Connection refused to host: 127.0.0.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM