docker app postgres本地连接

时间:2018-01-19 02:52:27

标签: postgresql docker

我创建了一个带有playframework后端的docker镜像,后端连接到pgsql localhost数据库。我在本地机器上运行时运行顺畅,但是当我在docker中运行它时会收到错误。

我想将docker容器连接到我的posgresql localhost。

我已经尝试配置postgresql.conf和pg_hba.conf来打开端口5432

的pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS             

    METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    all             all             192.168.1.0/24          trust
host    all             all             172.17.0.0/16           trust
host    all             all             0.0.0.0/0               md5
# IPv6 local connections:
host    all             all             ::1/128                 trust
host    all             all             ::/0                    md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             172.17.0.0/32            trust
host    replication     all             ::1/128                 trust

postgresql.conf中

listen_addresses = '*'      
                    # what IP address(es) to listen on;
                    # comma-separated list of addresses;
                    # defaults to 'localhost'; use '*' for all
                    # (change requires restart)
port = 5432 

运行我的playframework应用程序时。我收到以下错误

Caused by: com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization

Caused by: org.postgresql.util.PSQLException: The connection attempt failed.

另外,使用brew安装postgresql,正确运行可以使用pgadmin4访问数据库。

0 个答案:

没有答案