【问题标题】:Can not connect to postgres db from datagrid无法从数据网格连接到 postgres db
【发布时间】:2018-10-20 11:10:05
【问题描述】:

我无法从 datagrip(jetbrains 应用程序)连接到 postgres。我正在尝试连接,但收到此消息

    Connection to postgres@172.18.0.3 failed.
[08001] Connection to 172.18.0.3:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

昨天一切都很好。我的数据库在 docker 容器中,有 yml 文件:

postgres_host:
    image: postgres:10-alpine
    restart: always
    ports: ["5433:5432"]
    volumes:
      - /tmp/lib:/var/lib/postgresql/data/pg_data
    environment:
      - PGDATA=/tmp/lib

我可以从终端连接到数据库,我使用了 select inet_server_addr( ), inet_server_port( );并且知道我知道主机和端口

 inet_server_addr | inet_server_port 
------------------+------------------
 172.18.0.3       |             5432

但是这些信息对我没有帮助,我有同样的结果 enter image description here

【问题讨论】:

    标签: database postgresql docker datagrip


    【解决方案1】:

    端口的映射ports: ["5433:5432"] 意味着postgres docker 容器在主机系统的localhost:5433 上可用。

    容器在其网络中相互通信,因此您可以从另一个容器访问postgres_host:5432 上的postgres 容器,该容器由docker-compose 在同一网络中创建。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-06
      • 1970-01-01
      • 2020-04-04
      • 2020-12-01
      • 2019-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多