簡體   English   中英

Pgadmin4 無法連接到我的 postgres 數據庫

[英]Pgadmin4 cannot connect to my postgres database

這是我的 docker-compose.yml 文件:

version: "3.5"
services:
  db:
    image: myapp
    container_name: my-database
    environment:
      POSTGRES_USER: myuser
      POSTGRES_PASSWORD: mypasswd
      POSTGRES_DB: mydb
    expose:
      - "5432"
    ports:
      - 8000:5432
    volumes:
      - /path/to/my/migrationsV1_0__audit_table.sql
      - //path/to/my/migrations/V1_1__tables.sql
  pgadmin:
    image: dpage/pgadmin4
    ports:
      - 5454:5454/tcp
    environment:
      - PGADMIN_DEFAULT_EMAIL=admin@mydomain.com
      - PGADMIN_DEFAULT_PASSWORD=postgres
      - PGADMIN_LISTEN_PORT=5454

然后我 $ docker inspect xxxxxxxx | grep "IPAddress" docker inspect xxxxxxxx | grep "IPAddress"

它產生 output:

    "SecondaryIPAddresses": null,
    "IPAddress": "172.17.0.2",
            "IPAddress": "172.17.0.2",

在 docker-compose 之后,我將值輸入到 pgadmin 中,如下所示:

Pgadmin_capture

然而 pgadmin 給出了錯誤:

無法連接到服務器

超時已過。

這里有什么問題?

在您的配置中,PostgreSQL 數據庫有 5432 端口(默認值)。 你確定在這一行嗎?

PGADMIN_LISTEN_PORT=5454

嘗試將其替換為

PGADMIN_LISTEN_PORT=5432

要解決此問題,只需使用--user=root運行容器(在 docker-compose 中使用user: root

您需要使用 Postgres 容器的網關地址。 使用docker inspect xxxxxxxx | grep Gateway docker inspect xxxxxxxx | grep Gateway來獲取它。 我猜你的情況是172.17.0.1

就我而言,我的 pgadmin 容器沒有共享數據庫容器的 .network。 所以,你應該運行這個命令。

docker network inspect NETWORK <YOUR DB CONTAINER'S NETWORK>

如果沒有,請運行此命令

docker network connect <YOUR_DB_CONTAINER'S_NETWORK>  <YOUR_PGADMIN_CONTAINER'S NAME>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM