【发布时间】:2020-04-24 08:21:26
【问题描述】:
我正在从 docker-compose 运行我的代码,它试图访问本地数据库 (postgres)。 每当我尝试运行时,都会出现此错误
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.
但 postgres 正在端口 5432 上运行
这是sudo netstat -ltnp | grep postgres的结果
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 1995/postgres
我在 ubunto 操作系统上使用 postgres v 10.9。
【问题讨论】:
-
如果您尝试访问容器内的本地主机,那么它是容器的本地主机,而不是您的机器或任何其他容器。如果您的应用和数据库都在同一个 compose 中声明,请使用相同的网络,您可以使用容器名称。
-
请在此处提供您的 docker compose 文件
标签: java postgresql docker ubuntu