[英]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:根据我对你问题的理解,以下是我的假设:
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:一些建议:
docker-compose
file if you will).docker-compose
文件中)。 You can always do a port mapping in order to access it from your Postbird. Here are the steps to migrate the Postgres server to using docker container以下是将 Postgres 服务器迁移到使用 docker 容器的步骤
docker-compose
with a new db service: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
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 实例,则无需进行上述更改,只需执行其他步骤:
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.