Docker 撰写 Postgres 总是因超时或连接被拒绝而结束

Docker Compose Postgres always ended by timeout or connection refused

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

所以基本上,我创建了一个 docker-compose with Postgis (Postgres)。我想通过 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 IP 地址 - 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 我一直有信息(它停止因为我 运行 停止 Postgresql)

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

谢谢大家