簡體   English   中英

從主機遠程連接到容器中的數據庫?

[英]Remotely connect to Database in Container from Host Machine?

我有一個在容器內運行的 Psql。 我可以通過運行這個來通過命令行連接

docker-compose exec api-db psql -U {username} {databasename}

在此處輸入圖像描述 但是如何通過 GUI 應用程序連接到它

我應該使用什么作為主機?

可能嗎?

我想你所說的“GUI 應用程序”是指像 PgAdmin 或你最喜歡的 IDE 這樣的 postgres 客戶端?

您只需要配置您的客戶端數據源,正如我們在您的日志中看到的那樣,我的意思是:

host : localhost
port : 5432 (or the one mapped in your docker-compose.yml file)
database : It's not "monitor" as it doesn't find it !
user and password : in your docker-compose.yml too. Visibly it's not "root" as id doesn't find it.

您的 docker-compose.yml 應該是您項目的根目錄。

如果您的 docker-compose 中缺少它,您可以添加它:

version: "3.7"
services:
  main:
    image: postgres:12.7-alpine
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=root
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=monitor

此致。

暫無
暫無

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

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