I should have a way to access host machine from within container.
Actual behavior
Cant figure out how to do that with docker for mac beta
Information
With the change to all the docker images running on localhost and the ditching of virtualbox (which from what little I understand, made networking more difficult), I would think there would be a standard way to access the host machine from within the docker container. Is there a way to do this with docker for mac? All the docs regarding doing so seem to only be relevant to the virtual box version and docker-machine
In my case, I am running a data visualization app (looker), which needs to whitelist the url of the main application, to allow embedding of iframes under that ip/domain. So in development, the iframes donāt resolve, because there is no way for looker to know the ip of the host machine which is running my rails app.
Basically the dependency stack is
Rails
āpostgres
ārabbitmq
ālooker
----mysql
Links wonāt work because I, like many others from what I could gather on these boards, donāt want to run the main application (rails) in a docker container, in development. It will only make development/debugging more difficult.
An example would be running an nginx container, which reverse proxies requests back to the host for a web application.
The web application is not in a container because itās a heavy grails app with multiple dependencies, and will be a container eventually but itās not currently.
The main problem for me was to reliably find out the IP address of the host. So in order to have a fixed set of IPs for both my host and my containers Iāve set up a docker network like this:
Now each container can connect to the host under the fixed IP 192.168.0.1.
You just need to make sure, that you connect all your containers to that ādockernetā network you just created. You can do that with the --net=dockernet option for docker run. Or from a docker-compose.yml:
Another example would be running a php application that has xdebug set up on it. In order to debug, the server must connect to the ide with an ip address that is defined in the configuration. At the moment, I have to hardcode the ip address of the host machine into that configuration file.
I recently created a repo to address the host<->container connectivity issues in Docker for Mac. Itās not an ideal solution by any stretch (itās very much a hack), but it does suffice for local development. It does have limitations; it only supports a single named host network right now, and must be re-run each time the Docker daemon is restarted (check the Readme). When used in itās default configuration running ifconfig on your host machine should reveal a new tap1 interface, the IP reported there may be used inside containers connected to named bridge network to access the host machine.
Thereās also docker.for.win.localhost for Docker for Windows users.
What Iād really like though is a method to do this cross-platform - We have Linux and Windows users that use the same docker-compose.yaml - docker.for.win.localhost will mean nothing to half of them. Any suggestions?