繁体   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