1
I am setting up a Vagrant box with a development environment. I have some web apps running, some more services, a database and a docker inside Vagrant. Most services are used internally and I do port forwarding for web apps which I can access in my host machine with localhost:FORWARDED_PORT
.
But one of these web apps needs some JavaScript running in docker. So it needs to access it from my web browser in the host machine. Internally, I can see this:
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 56:84:7a:fe:97:99 brd ff:ff:ff:ff:ff:ff
inet 172.17.42.1/16 scope global docker0
valid_lft forever preferred_lft forever
The service running in Docker is providing some static JS on http://172.17.0.2:4567
. I need to be able to access that internal address from the web app in the host machine, how can I set that up?
This doesn't seem to work. Even if I set the port on the docker run command, the js is still being served on the :4567 ip. If I curl the js file from vagrant ssh, it is working. So what I would need to do is make http://172.17.0.2:4567 from the guest machine to be available on the host machine (preferrably with the same ip/port configuration). I tried adding the
– Fernando Briano – 2014-10-14T18:16:03.823guest_ip
andhost_ip
parameters to a port forwarding config on the Vagrantfile but it doesn't work either. Is there a way to accomplish that via port forwarding?There are two players there, vagrant (that may have a valid external ip or a NATed one with forwarded ports), and docker, that by default have its own internal network but can put ports as they were from the host, and you should forward the port at the two levels. An alternative would be using --net=host in docker, that would use the same network as the host, so that container will be listening at the vagrant box ip for that port. In none of this cases you would be listening at the internal docker ip, for a single port is just not needed. But whatever calls it should be at the external IP. – None – 2014-10-14T18:33:51.600