skip to Main Content

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)
enter image description here
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


  1. Chosen as BEST ANSWER

    You can skip a step if you've already done it

    1. Using psql, alter the authentication credential of default postgres user, postgres with the following commands
    sudo -u postgres psql
    ALTER USER postgres PASSWORD 'newPassword';
    

    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;

    1. Modify /etc/postgresql/13/main/pg_hba.conf and add host all all 0.0.0.0/0 md5 to the end of the file

    2. Modify the pgadmin_docker_env.list file to include your choice port

    PGADMIN_LISTEN_PORT=8000
    
    1. Stop the previously running container pgadmin docker stop pgadmin and remove the containerdocker rm pgadmin. Then run docker 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 mode

    2. Run localhost:8000 in your web browser and create a server connection using the same connection parameter as in the screenshot.


  2. 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 of localhost.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search