How to map local postgres 5432 port to dpage/pgadmin4 container?

My current installation is like this:

  • I am running postgres11 on EC2 instance via the package manager.
  • Running dpage/pgadmin4 and mapping 4499:80. The web UI is hosted at port 80 of the host.

I can access pgadmin page on http://localhost. But from there I can’t connect to the system’s local 5432. This is because this is out of the Docker world and does not know about the mapping.

When I -p 5432:5432 with dpage/pgadmin4 , I get this error:

docker: Error response from daemon: driver failed programming external connectivity on endpoint vibrant_ptolemy (8773c583574f427176fb1447b7c2e91643b1df460be526c800fc45a53ee02557): Error starting userland proxy: listen tcp 0.0.0.0:5432: bind: address already in use.

How can I map local postgres to docker container?

Hi
to solve your backup problem,
you can extract database into a script dump file using pg_dump. Dump file will be stored in current directory.

if your question is about the way that a process inside docker container gets access to a port on the docker host, you can do this with several methods
use of “host.docker.internal” as the postgresql address in the configuration of pgadmin4 is the most common.
This can be used with docker version 18.03 or upper. If you have to need older versions let me know

Hi @sudolg, thank you for the pg_dump method. I will research that more.

For the host.docker.internal method, can you tell more about that?
Currently, I am getting this when putting that address in the host name input. Seems like DNS isn’t getting resolved.

I have Docker version 19.03.13-ce on Amazon Linux.

“Address already in use” makes it appear that some other process on your hosting instance. I would think that there is a separate PostgreSQL running on that instance.