This is from a note I wrote in 2017, there is likely a better way to do this in modern Docker.
Inside the container run
sudo ifconfig lo0 alias 10.0.2.2. This will add 10.0.2.2 as an alias for the loopback interface
Now, the container can talk to the host by targeting 10.0.2.2
Written by Alex Wendland, who is currently exploring fintech at Pinwheel. Here's a Twitter handle, a GitHub, some LinkedIn, ol' Facebook, or a hip Instagram if you're interested.