0

Goal:
Enter the docker desktop's container PostgreSQL by using the installed PgAdmin in my local computer (not that container that contain pgAdmin)

Background:
I was manage to have two different container, one for postgresql and the second one is the pgadmin. (https://dev.to/shree_j/how-to-install-and-run-psql-using-docker-41j2)

In order to enter the container's postgresql I needed to retrieve the container's ip adress (How to get a Docker container's IP address from the host)

Then I was managed to enter the container's postSQL by using the container's pgAdmin.

Problem:
The next phase to to use the local and installed pgadmin in order to enter the container's database.

The same content of hostname/address, port, username and password I was using for the container's pgadmin, I used the same content for the local pgadmin.

I retrieve the message "Unable to connect to server:"

What part am I missing in order to enter the container's PostGreSQl by using the local pgadmin?

Info:
*Using win 10 pro

HelloWorld1
  • 13,688
  • 28
  • 82
  • 145

1 Answers1

0

where you deploy the postgreSQL docker ? if you using wsl2 on windows 10:

  • docker run --name postgresql-container -p 5432:5432 -e POSTGRES_PASSWORD=somePassword -d postgres

if you have postgre locally you have to change the port to eg: -p 5431:5432

then you have to check your wsl ip (here i'am using ubuntu 20.04 image)

run this command ip -4 addr show eth0

it will showing your ip information that you can use later

4: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    inet 172.17.89.133/28 brd 172.17.89.143 scope global eth0
       valid_lft forever preferred_lft forever

my ip was 172.17.89.133

ariefs
  • 569
  • 1
  • 4
  • 16
  • "ip -4 addr show eth0" don't work. I'm using win10 pro – HelloWorld1 May 16 '21 at 14:11
  • are you running docker on wsl2? – ariefs May 17 '21 at 00:06
  • this command run on my ubuntu 20.04 distro on wsl2.. if you not use wsl2, try this one run : docker run --name postgresql-container -p 5431:5432 -e POSTGRES_PASSWORD=somePassword -d postgres * notice that you have to change the port to 5431(the port actualy is up to you) than you can input localhost as hostname, and port to 5431 on you pgadmin4 create-server popup.. – ariefs May 17 '21 at 00:30
  • "re you running docker on wsl2" I'm not sure. How do I find out? – HelloWorld1 May 17 '21 at 14:45
  • you can install it by following this [docs](https://learn.microsoft.com/en-us/windows/wsl/install-win10) , [docs2](https://docs.docker.com/docker-for-windows/wsl/#:~:text=From%20the%20Docker%20menu%2C%20select,Click%20Apply%20%26%20Restart.) also this [blog](https://www.hanselman.com/blog/how-to-set-up-docker-within-windows-system-for-linux-wsl2-on-windows-10) – ariefs May 19 '21 at 02:22