如何使用pgAdmin在Docker容器上连接Postgresql映像? [英] How to use pgAdmin to connect postgresql image on a docker container?

查看:295
本文介绍了如何使用pgAdmin在Docker容器上连接Postgresql映像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从GitHub克隆了一个项目,并在自述文件中要求我运行 docker-compose up 以运行PostgreSQL映像...

I just cloned a project from GitHub and in the readme file it asks me to run docker-compose up to run the PostgreSQL image...

我假设运行命令后,PostgreSQL服务器映像将使用端口5432在PC上的Docker容器中启动。然后运行 npm install npm start 启动项目(数据库表将使用ORM框架自动创建)。但是,当我打开pgAdmin连接到服务器时,它说连接成功,但是找不到创建的表。在这里,我想pgAdmin在5432上没有连接PostgreSQL服务器(Docker映像)...所以我的问题是,是否可以使用安装在本地PC中的pgAmin连接到已经运行的PostgreSQL服务器Docker映像,映射到我本地PC的端口5432?

I assume that after I run the command, the PostgreSQL server image will start in the Docker container on my pc using port 5432. Then I run npm install and npm start to start the project (the database tables will be automatically created using an ORM framework). However, when I open my pgAdmin to connect to the server, it says it successfully connected but I could not find those tables created. Here I guess the pgAdmin didn't connect the PostgreSQL server (Docker image) on 5432... So my question is whether it is possible to use pgAmin installed in my local pc to connect to the PostgreSQL server Docker image which is already running, mapping to the port 5432 of my local PC?

推荐答案

docker ps --format table {{ .Names}} \t {{。ID}} | grep‘postgres’

上面的命令将提供通过docker运行的Postgres容器的容器名称和ID的列表。如果您有多个Postgres容器,请选择要在Pg-Admin中添加的容器,并将该Postgres容器的容器ID用于下一个命令

The above command will give a list of containers name and Id of Postgres container running via docker. if you have multiple Postgres container, pick one that you want to add in Pg-Admin and use the container id of that Postgres container for next command

docker检查<容器ID> | grep -E -A 1 IPAddress |端口

它将提供您要通过PG连接的Postgres容器的IP地址和端口-管理员。使用该IP地址和端口通过Pg-Admin连接

It will give the IPAddress and port of Postgres container you want to connect via PG-Admin. Use that IPAddress and Port to connect via Pg-Admin

这篇关于如何使用pgAdmin在Docker容器上连接Postgresql映像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆