I cannot connect local pgadim to a container that runs postgres - postgresql

i have an issue
i have a container that has a web application running and a postgres db, when i launch the webapp is connected in database correctly, but when in local i tried using a pgadmin that is install on my machine and i try to connect to database of container it gives me an error connection
error message
TIPS
the container has the port-forward of database
i tried using both localhost and the ip of container as host when initialize connetion using pgAdmin
I have no idea how to do that, someone can help me

Related

Connect to a remote database running in a Docker container from another container running on different machine

I am facing the following situation:
I have a docker container (db) running a PostgreSQL database on my machine.
Furthermore, currently I have another container (server), which can successfully connect to that database from the same machine.
However, what I want is to connect to the db database from the server container, even if it is running on different machine. How could I do that?
I found this: https://www.codegrepper.com/code-examples/whatever/how+to+connect+to+remote+postgres+database+from+command+line
and this: https://www.a2hosting.com/kb/developer-corner/postgresql/remote-postgresql-connections#Method-2.3A-Set-up-a-direct-connection.
Both solutions make connection to the machine running the db container through ssh. However, I can whitelist only some valid users to be able to ssh to the machine running the db container, but not the user (which is the root) of the server container.
I hope my question is clear!
Thanks for any help!
p.s.: both containers are defined in a docker-compose file.

Connection problem with postgresql and docker

I'm running a composition of docker containers of a preexisting project on Ubuntu 20. One container for apache2, one for postresql. I can connect to the webserver through my browser and the webserver container establishes a connection to the postgresql container - so far everything works.
The problem is: I can't establish a connection from my host machine to the postgresql database using php. Whenever I try, I get an password authentication failed for user .. error.
I know that the php code, the username and the password are correct, as all three work when I execute them from within the webserver container.
$db_connection = pg_connect("host=db dbname=MYDB user=MYUSER password=MYPASS");
I configured /etc/hosts on my host to resolve "db" to 127.0.0.1 and also tried using host=localhost. Both didn't help.
Am I getting something wrong about how docker works? I found a couple of OSX solutions which were talking about docker containers running in virtual machines and therefore not being accessible from the host... Which is confusing, as apache2 is reachable from my host.
I did my research on stackoverflow tried solutions from e.g. Connecting to Postgresql in a docker container from outside but they didn't work for me.

Docker: Unable to connect to a remote Postgres server from a Docker Container

I installed the Metabase application, created a Docker container (on one Linux host) and I want to connect to a remote Postgres database (on a second Linux host) from the Docker container. The setup of Metabase allows entry of connection parameters to the Postgres database. Each time I enter the proper connection parameters in Metabase I get a database connection error. I can connect to the Postgres database from the host running the container using PSQL with no problem. My question is, is there something within Docker or the remote Postgres server that I must setup in order to allow a connection between a Docker container and a remote database? I realize this is normally caused by incorrect host/port information, problems with DNS, firewall blocking or other network problems. I am new to Docker and I do not know where to look or what to setup to make this work. Does anyone have suggestions about how to make this connection work? Thank you!

Docker container, running PostgreSQL not allowing php's pg_connect from another container

I have the following architecture:
A network with 3 containers:
container_db, running PostgreSQL
container_pg_admin, running a simple pgAdmin environment
container_php_dev, running the whole environment, needed for the application to function properly (nginx, php, angular for the frontend, etc.)
When I try to pg_connect() from container_php_dev to container_db the connection gets refused. This is the actual error message I get: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: No route to host↵ Is the server running on host "container_db" (172.18.0.4) and accepting↵ TCP/IP connections on port 5432?.
However, when I try to connect to container_db from container_pg_admin I face no problem achieving this (host is container_db and port is 5432). Even if I map port 5432 of container_db to 5555 on host, I'm able to connect to 127.0.0.1:5555 from DBeaver or other DB Manager (TeamSQL).
All containers were restarted a few times as well as docker itself. And as this is my development machine, the host PC was restarted as well.
What might be the problem, how to diagnose and possibly solve? Have any of you experienced such strange docker behaviour?
Try running the container_db in the hosted network using flag --network host

Connect to database in docker container on remote host with pgadmin3

I'm trying to connect to a database running in a docker container on a remote host. I configured SSH-Tunnel in pgadmin3 with ip of the host and identity file. On Settings tab I inserted 172.18.0.2 (the container IP) as host. It is not possible to connect. pgadmin turns grey for a while and presents me a beautiful error message:
SSH error: Error when starting up SSH session with error code -8 [Unable to exchange encryption keys]
Do I miss something? Is it possible to connect to the container?
When I upgraded pgAdmin 1.20.0 to 1.22.1, I started getting the same error. pgAdmin 4 doesn't have support for any SSH tunnel either. So, the only option you have right now is .. revert back to 1.20.0. Unfortunately, if you're on PG9.5 or better, pgAdmin 1.20.0 doesn't support it.
If you require access to a Postgres 9.5 database, you can manually create the SSH tunnel, and then connect using pgAdmin3 by setting the host to localhost. On Linux or Mac, you can use the following: ssh -L 5432:<pg-host>:5432 <jump-host-ip-or-dns>. It doesn't seem likely that pgAdmin3 will receive any updates with the direction pgAdmin4 is heading.