Docker Community Forums

Share and learn in the Docker community.

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?

It’s a valid question don’t know why people feel “doesn’t seem possible to answer that question”.

So, here’s how I do what you are trying to do:

Pull postgres image from Docker Hub

docker pull postgres:latest

Run the container using the below command

docker run -p 5432:5432 postgres

Using docker’s inspect command find the IP

Use that IP, PORT, Username, and Password to connect in PGADMIN

You can also do a simple telnet like below to confirm if you can access docker postgres container:

telnet IP_ADDRESS 5432

1 Like

That’s a good reason to use Docker image for postgres. But what if I don’t want to use Docker for postgres?

I want this because it would be easy to backup my database when I terminate my EC2 instance. What can I do to manage backup when using Docker container? Any idea? :thinking:

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.