【问题标题】:Docker Compose Postgres always ended by timeout or connection refusedDocker Compose Postgres 总是以超时或连接被拒绝而结束
【发布时间】:2021-04-05 03:37:03
【问题描述】:

这里有个小问题。我想我刚才做错了什么,但我找不到在哪里,我转身已经 +2 小时了。

所以基本上,我用 Postgis (Postgres) 创建了一个 docker-compose。我想通过 Tableplus 连接它。 但是,我不能...

2种错误不断出现:

  1. 当我尝试基本在 127.0.0.1 上连接时,它一直告诉我连接被拒绝
could not connect to server: Connection refused
    Is the server running on host "127.0.0.1" and accepting
    TCP/IP connections on port 5432?

  1. 当我尝试使用 docker IPAddress - 172.23.0.2(docker 检查图像的 ID 以获取图像的 IP 地址)时
could not connect to server: Operation timed out
    Is the server running on host "172.23.0.2" and accepting
    TCP/IP connections on port 5432?

这是我的 docker-compose.yml

version: '3.5'


services:
  db:
    image: kartoza/postgis:12.1
    environment:
      - POSTGRES_USER=user1
      - POSTGRES_PASSWORD=password1
      - POSTGRES_DB=database_db
    volumes:
      - data_db_volume:/var/lib/postgresql/12
    ports: 
      - "5432:5432"
    
volumes: 
  data_db_volume:

起初,当我尝试连接时,它告诉我:角色 user1 不存在。

为了阻止这种情况,我在我的机器上运行了:brew services stop postgresql

我认为 psql 是在同一个端口上本地运行的,因为 lsof -n -i:5432 | grep LISTEN i 一直在获取信息(自从我运行 stop Postgresql 后它就停止了)

【问题讨论】:

  • 你试过用 localhost 或 0.0.0.0 代替 127.0.0.1 吗?
  • 嗨@PanagiotisBougioukos,是的,两者都导致相同的结果:连接被拒绝:(
  • 然后数据库运行良好,但它只是拒绝连接(可能是因为防火墙)。在这里查看stackoverflow.com/a/41161674/7237884
  • 嗨@PanagiotisBougioukos,我检查了,我的配置已经和你发给我的答案一样,我也检查了pg_hba.conf,接受外部连接似乎是正确的......我输了......

标签: postgresql docker docker-compose psql


【解决方案1】:

好吧,经过几天的研究并在另一台计算机上尝试,它似乎来自 2 点:具有图形界面的新 docker 软件,我以前没有使用过,一旦它运行正确并从这个地方一切都开始正常工作,所以我认为由于软件过时而导致错误。

谢谢大家

【讨论】:

    猜你喜欢
    • 2021-10-12
    • 2020-09-08
    • 2019-01-02
    • 2019-11-12
    • 2021-05-26
    • 2018-07-03
    • 2021-03-23
    • 2022-01-01
    • 2016-03-08
    相关资源
    最近更新 更多