简体   繁体   English

错误:连接 ECONNREFUSED 127.0.0.1:5432 docker-compose up

[英]Error: connect ECONNREFUSED 127.0.0.1:5432 docker-compose up

Not sure why am I getting the SequelizeConnectionRefusedError.不知道为什么我会收到 SequelizeConnectionRefusedError。 I verified that I am able to run all my docker images locally but when I try to run 'docker-compose up' command, I am running into Error: connect ECONNREFUSED 127.0.0.1:5432.我确认我能够在本地运行我的所有 docker 镜像,但是当我尝试运行“docker-compose up”命令时,我遇到了错误:connect ECONNREFUSED 127.0.0.1:5432。 在此处输入图片说明

Based on my understanding of your question, here are my assumptions:根据我对你问题的理解,以下是我的假设:

  • You are using MacOS您正在使用 MacOS
  • Your Postgres server is running in the host OS instead of in another docker container.您的 Postgres 服务器正在主机操作系统中运行,而不是在另一个 docker 容器中。

With that being said, this is a common problem with MacOS users who want to connect their docker containers to the Postgres server running in the host machine.话虽如此,对于想要将他们的 docker 容器连接到主机中运行的 Postgres 服务器的 MacOS 用户来说,这是一个常见问题。 As they are not in the same network, there is no way for your container to reach the Postgres server and hence, connecting to it via 127.0.0.1:5432 will definitely not reachable.由于它们不在同一个网络中,因此您的容器无法访问 Postgres 服务器,因此,通过127.0.0.1:5432连接到它肯定无法访问。

It will be trivial to solve in a Linux machine by adding network_mode: host so that the containers will be running in the same network as host machine hence is able to reach the Postgres server.通过添加network_mode: host来解决 Linux 机器中的问题将是微不足道的,这样容器将与主机在同一网络中运行,从而能够访问 Postgres 服务器。 However, due to the implementation of Docker on Mac where Docker host is actually being run in a hidden VM on top of your MacOS, this solution will not work here.但是,由于 Docker 在 Mac 上的实现,其中 Docker 主机实际上是在 MacOS 之上的隐藏 VM 中运行的,因此该解决方案在这里不起作用。

Some suggestions:一些建议:

  1. Migrate your Postgres server to run in a docker container (in the same docker-compose file if you will).迁移您的 Postgres 服务器以在 docker 容器中运行(如果您愿意,可以在同一个docker-compose文件中)。 You can always do a port mapping in order to access it from your Postbird.你总是可以做一个端口映射,以便从你的 Postbird 访问它。
  2. Or if you still insist on running it locally in your MacOS, here is a workaround that involves creating another docker container in the same docker network and perform a revert SSH tunneling.或者,如果您仍然坚持在 MacOS 本地运行它,这里有一个解决方法,涉及在同一个 docker 网络中创建另一个 docker 容器并执行恢复 SSH 隧道。

Here are the steps to migrate the Postgres server to using docker container以下是将 Postgres 服务器迁移到使用 docker 容器的步骤

  1. Update your docker-compose with a new db service:使用新的 db 服务更新您的docker-compose
db:
    image: postgres:10.5-alpine
    environment:
        POSTGRES_USER: $UDAGRAM_USERNAME
        POSTGRES_PASSWORD: $UDAGRAM_PASSWORD
        POSTGRES_DB: $UDAGRAM_DATABASE
    ports:
        - 35432:5432
    volumes:
        - <path where you want to persist your database data>:/var/lib/postgresql/data
  1. You can now connect to your new postgres using Postbird at localhost:35432您现在可以在localhost:35432使用 Postbird 连接到您的新 postgres

EDIT 1编辑 1

If you run your Postgres instance in AWS RDS, you will not need to make the changes above but follow other steps:如果您在 AWS RDS 中运行 Postgres 实例,则无需进行上述更改,只需执行其他步骤:

  • Make sure that your network can reach the RDS endpoint at port 5432. A best practice here is to update the security group inbound rules to allow only port 5432 from only your IP address (how to do that is out of the scope of this answer but can easily be found from AWS documentation)确保您的网络可以在端口 5432 到达 RDS 端点。这里的最佳做法是更新安全组入站规则,以仅允许来自您的 IP 地址的端口 5432(如何做到这一点超出了本答案的范围,但可以从 AWS 文档中轻松找到)
  • Update the value of UDAGRAM_HOST to be the RDS endpoint which can be found from the AWS RDS console.UDAGRAM_HOST的值更新为可从 AWS RDS 控制台找到的 RDS 终端节点。

暂无
暂无

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

相关问题 错误:连接 ECONNREFUSED 127.0.0.1:5432 docker migrate - ERROR: connect ECONNREFUSED 127.0.0.1:5432 docker migrate 出现错误:连接 Redis 时在 docker-compose 中连接 ECONNREFUSED 127.0.0.1:6379 - Getting Error: connect ECONNREFUSED 127.0.0.1:6379 in docker-compose while connecting redis 错误:连接 ECONNREFUSED 127.0.0.1:5432 heroku - Error: connect ECONNREFUSED 127.0.0.1:5432 heroku 错误:在 Gitlab CI 上连接 ECONNREFUSED 127.0.0.1:5432 - ERROR: connect ECONNREFUSED 127.0.0.1:5432 on Gitlab CI 在docker-compose文件中将db:5432更改为127.0.0.1:5432 - change db:5432 to 127.0.0.1:5432 in docker-compose file 错误:无法连接到数据库:,SequelizeConnectionRefusedError:连接ECONNREFUSED 127.0.0.1:5432 - error: Unable to connect to the database:, SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:5432 带有Postgres的GitLab CI错误:连接ECONNREFUSED 127.0.0.1:5432 - GitLab CI with Postgres ERROR: connect ECONNREFUSED 127.0.0.1:5432 出现错误:在 Github Actions 中连接 ECONNREFUSED 127.0.0.1:5432 - Getting ERROR: connect ECONNREFUSED 127.0.0.1:5432 in Github Actions 错误:在 TCPConnectWrap.afterConnect 处连接 ECONNREFUSED 127.0.0.1:5432 [as oncomplete] - Error: connect ECONNREFUSED 127.0.0.1:5432 at TCPConnectWrap.afterConnect [as oncomplete] (节点:1184)UnhandledPromiseRejectionWarning:错误:连接 ECONNREFUSED 127.0.0.1:5432 - (node:1184) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:5432
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM