How to reach MacOSX from Container?

Hello,

I would like to use a docker container to run NodeJS Stack (node, grunt, npm, bower, hell…).
Docker is perfect for that. Therefore the SPA into container need to speak with the backend installed on MacOS (not into a container because dev mode). So how can i contact the local host ?

Thanks a lot.
Best regards,

The Mac’s localhost (127.0.0.1) IP is translated to something inside the container. I think this varies from one system to the next, so you need to find out:
cat ~/Library/Containers/com.docker.docker/Data/database/com.docker.driver.amd64-linux/slirp/host
192.168.65.1

This means you can get to the Mac’s 127.0.0.1 from inside the container via 192.168.65.1.

I know of 2 options:

  • Pass in the host IP to the container as an environment variable so it knows about the IP.

  • Or have the container point to a known static IP (like 10.254.254.254). Then alias the host to that IP.

      ifconfig lo0 alias 10.254.254.254