while you connect from a non-dockerized application to the database running on the same computer using
127.0.0.1 this will not work if you try to connect from within a docker-container to a database running outside of the same docker-container.
But you can connect to
172.17.0.1 (the host-computer’s IP-address in Docker’s default network on a linux-machine) or
host.docker.internal (the same for Docker on Windows) from within a Docker-container to connect to a service running on your host-computer.
Keep in mind that you may
…need to adjust firewall-rules on your host-computer
…have to configure your database to not only listen to
127.0.0.1 but on other interfaces, too
…check that the rights granted to your database-user are also valid to connect from other hosts than
localhost as you are really connecting from a different source-ip-address.