Say for example you have a MySQL server running on the host machine and want your docker container to be able to connect to it.
When using docker-compose the following config in the yaml will allow this.
extra_hosts:
version "3"
services
app:
image: your/image:latest
extra_hosts:
- "host.docker.internal:host-gateway"
Now, inside your container to connect to the host use the address :
host.docker.internal
My scenario for requiring this, I have gluetun running as a container which connects to a wireguard VPN and also a socks5 proxy. All traffic in this container goes via the VPN.
I have a different container which I want to sit outside of the VPN, and those apps all communicate together. One of these proxies external requests via socks5. If I move that app to the gluetun compose the other apps can no longer see it.
- https://hub.docker.com/r/qmcgaw/gluetun
- https://hub.docker.com/r/serjs/go-socks5-proxy/