0

I'm trying to connect postgresql and pgadmin4 work together. pgadmin4 works fine but when I try to create a new server I have 2 problems:

  • if the postgres container is at other port that is not 5432 it dont recognize that port. It show this error: could not connect to server: Connection refused Is the server running on host "172.17.0.5" and accepting TCP/IP connections on port 5431?
  • if the postgres container is at port 5432 the error is FATAL: password authentication failed for user "example".

I execute this command to get postgres container: docker run -p 5431:5432 --name postgres2 -e POSTGRES_PASSWORD=ad1234 -d postgres.

I try, following other responses in stackoverflow, adding this command -c"listen_addresses='*'" and I enter in the config file too but noone of this work to me.

Hope you can help me, thanks.

EDIT [Solved]

Ok I solved, it was a big fail by my part. I was using 172.17.0.5 (the IP container address) and what I need to use to connect is 172.17.01 (the Gateway). Thanks for you time.

Schwarz54
  • 964
  • 1
  • 9
  • 18
  • `Is the server running on host "172.17.0.5" and accepting TCP/IP connections on port 5431?` - well, is it? How have you tried to test that the IP and port are correct? – Richard Huxton Apr 30 '19 at 21:15
  • that IP is the postgres container IP, and port I think is correct because I redirect it when I ran it the first time `-p 5431:5432`. I execute the comand `docker inspect postgres2` and in the section of `network` i got this `"IPAddress": "172.17.0.5",` and in the section of `ports` got this `"Ports": { "5432/tcp": [ { "HostIp": "0.0.0.0", "HostPort": "5431" } ] ` – Schwarz54 Apr 30 '19 at 21:23
  • So, according to what you have just posted, it is not listening on 172.17.0.5;5432 is it – Richard Huxton Apr 30 '19 at 22:14
  • when I do `docker start -a postgres2` this is what I get `2019-04-30 22:26:32.062 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 2019-04-30 22:26:32.062 UTC [1] LOG: listening on IPv6 address "::", port 5432 2019-04-30 22:26:32.073 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 2019-04-30 22:26:32.122 UTC [24] LOG: database system was shut down at 2019-04-30 22:24:12 UTC 2019-04-30 22:26:32.128 UTC [1] LOG: database system is ready to accept connections ` – Schwarz54 Apr 30 '19 at 22:27
  • I answered this here: https://stackoverflow.com/questions/25540711/docker-postgres-pgadmin-local-connection/57729412#57729412 – Afshin Ghazi Aug 30 '19 at 15:30

1 Answers1

1

I have reproduce your scenario this way:

# docker run -p 5431:5432 --name postgres2 -e POSTGRES_PASSWORD=ad1234 -d postgres
# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
d4030c577a24        postgres            "docker-entrypoint.s…"   2 minutes ago      Up 2 minutes       0.0.0.0:5431->5432/tcp   postgres2

# sudo -u postgres psql -h localhost -p 5431
could not change directory to "/root": Permission denied
Password: 
psql (10.5, server 11.2 (Debian 11.2-1.pgdg90+1))
WARNING: psql major version 10, server major version 11.
         Some psql features might not work.
Type "help" for help.

postgres=# CREATE DATABASE mytestdb;
CREATE DATABASE
postgres=# \q

Now starting docker for pgadmin and being able to connect to postgresql:

docker run -p 80:80 --link postgres2 -e "PGADMIN_DEFAULT_EMAIL=user@domain.com" -e "PGADMIN_DEFAULT_PASSWORD=SuperSecret" -d dpage/pgadmin4

With the above command you can link the postgres2 docker to the pgadmin docker and then on creating a connection on pgadmin4 you should use:

  • host name/address: postgres2
  • port: 5432
  • Maintenance database: postgres
  • username: postgres

with that, I've connected to Postgres from pgadmin4

As far as I know, docker PostgreSQL comes by default with localhost only connection and if you want to add remote connection you should add "listen_addresses = '*'" to postgresql.conf

Colin Moreno Burgess
  • 1,432
  • 1
  • 12
  • 17