【发布时间】:2018-06-29 06:28:27
【问题描述】:
我有一台安装了 PostgreSQL 的服务器。我所有的服务都在容器中工作(docker-compose)。我想从容器中使用我的 Host PostgreSQL。购买我有错误:
Unable to obtain Jdbc connection from DataSource (jdbc:postgresql://localhost:5432/shop-bd) for user 'shop-bd-user': Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL State : 08001
Error Code : 0
Message : Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Connection refused (Connection refused)
我的 docker-compose 正在使用 host network_mode,如下所示:
version: '3'
services:
shop:
container_name: shop
build: ./shop
hostname: shop
restart: always
ports:
- 8084:8084
network_mode: "host"
我的数据库连接URL是:jdbc:postgresql://localhost:5432/shop-bd
【问题讨论】:
-
你要求 docker 端口
8084:8084而你没有说任何关于端口5432 -
@Krishna
8084是此服务的端口。其他服务可以通过http://localhost:8084与该服务进行通信。但它不适用于主机数据库。 -
显示您的
db服务配置的样子。它应该在端口下有5432:5432。 -
你在哪个操作系统上使用 docker?
-
@TarunLalwani 我在 Windows 上开发
标签: postgresql docker networking localhost docker-compose