Docker has its own networking space, trying to connect to the local IP Address of the container won’t work when the database is on the host machine.
Normally you would provide the hostname, ip address or use localhost if the database is installed on the same machine locally ie 127.0.0.1. But when the database is installed on the host machine that docker is running on top of we need a slightly different approach
What we need to do is add a loopback ip address to our local network card and connect the container to the loopback address
sudo ifconfig lo0 alias x.x.x.x up
sudo ip addr add x.x.x.x dev lo label lo:1