Docker Community Forums

Share and learn in the Docker community.

Connect to local pc from postgress container

Very good to everyone, I have a problem with a container, I hope you can help me.
I have an application in php that I connect from my local machine, to a postgres database, this connection is made through an SSH button using the MobaXterm software, to put them in context, configure a port of my local pc to a port of a Remote ssh and this connects to another server where the database is (configuration of the company where I work), everything works fine for me, and I implemented a container with XAMPP and it works perfectly, but when I run the php application, it does not connect me to the database, is there any way to connect from docker to the port of my host to make the request to the ssh server, thanks for your help.

Hello and welcome,

to connect to a port on your host from within a docker-container you can use 172.17.0.1 on linux (as 172.17.0.0/24 is docker’s default network and 172.17.0.1 is the host’s ip-address within) or host.docker.internal on windows.
Keep in mind that this is not identical to 127.0.0.1 on your host - you are connecting to your host via a network connection. So to use a host’s port create using port-forwarding you have to ensure that this is accepts connections from remove machines, too (which might create a security issue).