I pulled pgAdmin4 docker image into my linux debian machine and followed the process specified here to configure the container. I run docker run -p 8000:8000 --env-file ./pgadmin_docker_env.list -d dpage/pgadmin4
. For clarity, the pgadmin_docker_env.list specified in the command contains the environmental variables:: [email protected] PGADMIN_DEFAULT_PASSWORD=my_password
. With the container running in detached mode, I run localhost:8080 in my web browser to access pgAdmin 4 in server mode. However, I was unable to create a server connection to the localhost postgres database from inside the pgadmin. I got the following error after input of the connection parameters (shown in the screenshot attached below)
Unable to connect to server: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections?
UPDATE
I used host.docker.internal in place of localhost but I still got an error
Unable to connect to server: could not translate host name "host.docker.internal" to address: Name does not resolve
2
Answers
You can skip a step if you've already done it
Optionally, you can also create a user for your current account as a superuser with
CREATE ROLE user_name WITH LOGIN SUPERUSER CREATEDB CREATEROLE REPLICATION;
Modify /etc/postgresql/13/main/pg_hba.conf and add
host all all 0.0.0.0/0 md5
to the end of the fileModify the pgadmin_docker_env.list file to include your choice port
Stop the previously running container pgadmin
docker stop pgadmin
and remove the containerdocker rm pgadmin
. Then rundocker run --env-file ./pgadmin_docker_env.list --network="host" --name pgadmin dpage/pgadmin4
to run the container in host network mode. See more on host network modeRun localhost:8000 in your web browser and create a server connection using the same connection parameter as in the screenshot.
localhost
in this scenario refers to the PgAdmin container, where there is not a Postgres instance running.You want to connect to Postgres running on the host machine from the container (from what I can tell anyway?) so use
host.docker.internal
instead oflocalhost
.