I have created an ubuntu image with nginx, php and postgres.
I want to connect the postgres database in my current image with pgadmin
located on my loca
You can create a Docker bridge network to do this too.
$ docker network create pgnet
a0ae44aaf6f806fc37302e4c603b4828c4edb8d487fd9cd90e2fb19ae1d5c65f
$ docker run --detach \
--name pg \
--network pgnet \
--publish 5432:5432 \
--restart always \
--env POSTGRES_PASSWORD=pg123 \
--volume ${PWD}/data:/var/lib/postgresql/data \
postgres:12.1
b60611e43727dabe483c1f08fdf74961b886ce05b432a10a0625bd1b6db87899
$ docker run --detach \
--name pgadm \
--network pgnet \
--publish 8000:80 \
--volume ${PWD}/pgadmin:/var/lib/pgadmin \
--env PGADMIN_DEFAULT_EMAIL=user@domain.com \
--env PGADMIN_DEFAULT_PASSWORD=pgadm123 \
dpage/pgadmin4:4.20
27f9ce1c1c4c383ee1507f4e2d88f6ef33d4fcf5b209a8a03b87519f90d56312
Open http://localhost:8000/
The Hostname/address used above is the name of the Postgres container given by --name pg
In my case I could solve the problem inspecting my postgre image through command
docker inspect CONTAINER_ID | grep IPAddress.
So, I used the docker ip address to config my pgadmin 4 connection and everything was fine. Thanks to @Afshin Ghazi
This is what i did
docker run -p 5432:5432 --name container-postgresdb -e POSTGRES_PASSWORD=admin -d postgres
docker run -p 5050:80 -e "PGADMIN_DEFAULT_EMAIL=name@example.com" -e "PGADMIN_DEFAULT_PASSWORD=admin" -d dpage/pgadmin4
host: host.docker.internal
database: postgres
user: postgres
password: admin
It works fine!!!!!
What I have done success on windows 10 running docker for windows 1.12.6(9655), the step is like below:
Pull the latest postgres
docker pull postgres:latest
run the postgres containner:
docker run -d -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password123 --name db-my -p 5432:5432 --restart=always postgres
Then installed the latest version of pgAdmin4 from pgadmin website
Run pgAdmin 4 create new server, and input as following Host: 127.0.0.1 Port: 5432 User name: user password: password123
In order or find your IP of the container, use following command
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id
Referrence: How to get a Docker container's IP address from the host
For macOS IPs of postgres
and pgadmin4
are different from the ones docker inspect
provides.
Type
docker-machine ls
Take a look at the name of the server on the left. It's default
by default.
docker-machine ip default
will IP you need to use for both, pgadmin4
in browser and for postgres
in pgadmin4
settings.