datagrip连接不上 docker postgresql

我再用datagrip 连接 虚拟机中docker里的postgresql 时提示 尝试连线已失败。

img

但是在虚拟机中访问是没有问题的

img

这个问题怎么解决
本机和虚拟机的防火墙都关了

  • 你在虚拟机中是先进入docker,在docker中连接的数据库
  • 检查一下docker有没有映射对应的端口到宿主机,看看docker ps显示的5432端口是不是正确映射到宿主机对应端口了

亲,

  1. 你的虚拟机是192打头的ip
  2. netstat -an|grep 5432看看有没监听
  3. 如果步骤二没有,你把docker的网络模式设置为host或者不为host设置下-p 5432:5432

在配置文件 pg_hba.conf 增加一行 host all all 0.0.0.0/0 md5
数据库重启一下再连接试试。

[root@dem data]# cat 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
# IPv6 local connections:
host    all             all             ::1/128                 trust
# 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             ::1/128                 trust
host    all            all              0.0.0.0/0               md5

楼主搞定了吗?我也遇到这个问题