0

I have the following container: admin@PC:/$docker ps -a
returns

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9c0adfffff hg/sample:1.1 "/usr/sbin/init" 8 days ago Up 7 days 0.0.0.0:80->80/tcp, :::80->80/tcp agitated_euclid

This container is a springboot webapp, that maps the application on 80:80. So, the problem is how to access the postgresql that is used by this application inside the same docker container to be accessible from:

  1. the host linux machine containing the docker with this container? and,
  2. any computer with pgadmin interface to connect to this docker postgresql?

Currently I'm using sudo docker exec -it 9c0adfffff bash command to connect to the docker terminal and accessing database using psql, but that doesn't satisfy my current requirement. (like this)

I also tried docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres from this answer, but I think this fires up the new container, and also that is not what I need. I need to access database of existing container, whose webapp is running on port 80 currently.

hillsonghimire
  • 485
  • 5
  • 13
  • I'm confused. Is the container running a Spring application on port 80, or a PostgreSQL server? You'd almost always run these in two separate containers. Either way, if you publish the port of the database container `docker run -p 5432:5432` then you can connect to that published port with `psql` from the host without doing anything Docker-specific. – David Maze Apr 15 '22 at 11:18
  • its running spring application on port 80. – hillsonghimire Apr 15 '22 at 15:37

0 Answers0