For macOS and Windows
Docker v 18.03 and higher (since March 21, 2018)
Use your internal IP address or connect to the special DNS name host.docker.internal which will be host.docker.internal in the internal IP address used by the host.
Linux support expected https://github.com/docker/for-linux/issues/264
MacOS with earlier versions of Docker
Docker for Mac v 17.12 to 18.02
Same as above, but use docker.for.mac.host.internal .
Docker for Mac from 06/17 - 11/17
Same as above, but use docker.for.mac.localhost .
Docker for Mac 17.05 and below
To access the host machine from the dock container, you must attach an IP alias to your network interface. You can associate any IP address you want, just make sure you are not using it with anything else.
sudo ifconfig lo0 alias 123.123.123.123/24
Then, make sure your server is listening on the IP address mentioned above or 0.0.0.0 . If he listens for localhost 127.0.0.1 he will not accept the connection.
Then just point your dock container to this IP and you will have access to the host machine!
For testing, you can run something like curl -X GET 123.123.123.123:3000 inside the container.
The alias will be reset each time you reboot, so create a startup script if necessary.
The solution and additional documentation is here: https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds
Janne Annala Apr 21 '17 at 11:36 on 2017-04-21 11:36
source share