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.
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 :
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.