I noticed the missing docker0 interface on the host. The container does have a docker0 interface when run with --net=host and traffic does go from the container to the host just not the other way around. I am able to access services running on the host.
I need to run an nginx reverse proxy(which is probably a common scenario) that needs to access the host. If I run with --net=host the container has a docker0 interface that allows me to access the host. However if I throw in a -p 80:80 the port is not forwarded.
Can port forwarding and host networking be mixed to allow for the host to access some port on the container while the container uses the docker0 interface to access services no the host? Since the the two things run on different interfaces(eth0 and docker0) in the container maybe it would be possible?
Iāve also noticed that --net=host were not forwarded
I donāt exactly get what you are trying to achieve. But I donāt get how a lsof -ni TCP on the mac could display services.
From what I know and what Iāve seen, forwarding requests from your host to the container is done by the vpnkit:
Maybe there could be options to achieve what you want to do:
inspire from vpn implementations (tunnelblick, ā¦) to provide a VPN to the docker host networks (implement both an āinterfaceā on the mac and an interface on the docker host and exchange traffic from them as VPNKit does)
inspire from VPNKit to provide a VPN server on localhost that forwards traffic to the docker host
Although there is a risk of āinfinite loopā networking as containers are connecting to the world using VPNKit (VPNKit using the native mac networking)
When using DockerMachine, solving this was considerably easier.
All you needed to do was add a host-only or bridged adapter (depending on whether you wanted the container to see your whole network or just your machine) in VirtualBox. Then the host could communicate with a container running with the --net=host argument via that adapter, and the container was also able to talk to anything on the docker0 network.
Judging by the number of threads that have been popping up with similar questions to this one, this seems like a fairly common use case for a variety of purposes.
Canāt something similar be done with this new VM? Is creating host-only or bridged adapters not possible with xhyve?
Iām hoping a similarly simple solution will be found (or provided by the docker team if itās just not possible right now).
There should be a straightforward way to connect to a container running --net=host.
It should be similar.
I just spun up an ubuntu 16.04 in an instance of xhyve and it makes a NAT based network which allows me to access both the host from the VM and the VM from the host(see http://www.pagetable.com/?p=831). I think that with some routing magic the traffic could be routed from the VM to the containers(from the virtual nat interface to the docker0 interface).
So while I get this is a beta limitation at the moment I think(based on my crude assessment of the situation, mind you) there should be no technical impediment to implement this.
I wanted to slightly rephrase the original post to make sure Iām experiencing the same thing. Running Docker for Mac Version 1.12.0-rc3-beta18 (build: 9996) on OS X El Capitan 10.11.5
This works:
docker run --rm -p 80:80 nginx
(curl localhost from my Mac returns the nginx page)
This doesnāt work:
docker run --rm -p 80:80 --net host nginx
(curl localhost shows āFailed to connect to localhost port 80ā). However, a second container can connect: docker run --rm --net host alpine nc -vz localhost 80 returns localhost (127.0.0.1:80) open
This blocks how we use Docker for development, since we rely on --net host to expose a bunch of services that weād otherwise have to refactor to refer by container hostname. Can someone confirm that this isnāt intended? Or is this likely to not be fixed?
I did some experiments with xhyve and tap interfaces. The tap interface gives you gives you an ethernet interface pair through which you can access the vm without any nat in the way. In combination with libnetworks macvlan driver you can assign an ip address to containers which is directly reachable from os x. You can even access the container from remote machines with the correct routing in place.
Now I can just not find the right way to change the xhyve config from vmnet to vmnet tap. In earlier versions there was a -xhyve arguement pointing to xhyve.args file containing xhyve parameters. But this is not available in r18.