简体   繁体   中英

How to use pgAdmin to connect postgresql image on a docker container?

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...

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?

Yes, its possible you just have to get Ip address from Docker container, run the next commands to reach that.

docker ps

and then use the ID container to:

docker inspect ID container

Search by IPAddress from Docker config and use it to connect from pgAdmin.

docker ps --format "table {{.Names}}\\t{{.ID}}" | grep 'postgres'

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 inspect <container id> | grep -E -A 1 "IPAddress|Ports"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM