Jun 13, 2017 - At amazee.io, we use Docker Images to provide our clients the exact same services and configurations from production, for use as a local.
Yes, the docker daemon is running in xhyve. I understand that.
But this is application is a native OS X implementation of docker. Hence the question Should docker run –net=host work? If it should work, it doesn’t work currently and should be fixed. If it shouldn’t work, not expected to work, not going to be feasible, not on the roadmap, or whatever it would be nice to know this, and maybe have it documented somewhere. Also, if this is the case, the docker network host probably shouldn’t even be created in the first place.
To explain again: docker run -net=host should work. It does work.
It attaches to the ports on the host machine which is the virtual machine inside xhyve. If you expect it to connect to your Mac’s host ports, then no. It will not do that, because it’s running on a virtual machine. “ it’s similar to Docker Toolbox with a VirtualBox image running docker natively.” which didn’t support -net=host except insofar as using the host ports on the vbox machine, and not the OSX machine. Why would one ever think changing virtualization engines would change that? Snowgirl: To explain again: docker run -net=host should work. It does work.
It attaches to the ports on the host machine which is the virtual machine inside xhyve. Why would one ever think changing virtualization engines would change that? Because the overall direction of the Mac Beta has been to try to make it act more like native Linux Docker.
To give one specific concrete change, docker run -p 8888:8888 opens a port on the (Mac) host, not the xhyve VM, and if that was a Web-based service, I’d connect to and not (as in the Docker Machine setup). In fact, since docker run -p opens a real-host port but docker run -net=host only uses the VM ports, there are combinations of these (I use a Consul health checker that depends on -net=host, for instance) that work on Linux but not Mac. I find it merely frustrating and not a show-stopper, but it is an actual issue.
Yes, a -p works so well, because it’s opening a localport that is actually a redirect to an address that is NATed behind the docker bridged networking. It is not docker running on the Linux machine that is instigating this port opening. The invoking agent on the Mac knows exactly which port needs to be redirected and how. How could this work with -net=host? Docker in this case even the docker daemon running on the virtualized Linux machine doesn’t even actually know which port the container opened, because the container has done an “end run” around docker straight to the namespaced kernel. So, now, considering that the docker daemon doesn’t even know what port was eventually opened by the container, how would you expect the OSX invoker to even know?
Is the behavior inconsistent? Is there really anything they can do without essentially setting up a bridged NAT in the first place, and just replicating -p?
No, there really isn’t. Docker was designed with the intent that -p is the way things will work. (Otherwise, it can’t track the opened ports.) You might find it frustrating, but it is not a show-stopper, it is in fact, something that they cannot make work without instrumenting up the open TCP socket syscall in the Linux virtual guest, AND setting up a bridged network in the first place, and even then, ok, the container opens port 0, which is “random unprivileged port”, the Linux machine opens up port 64435 on it’s virtual linux host, but a different process running on the machine’s OSX host already has port 64435 (like, say a web-browser) open. Now, the Linux machine is stuck telling the host “hey, open up port 64435 and redirect it to me” and the host saying “no can do, it’s already open for a different program”.
Crash your container or return a “port already open” syscall error? Now the behavior is still different from Linux, because sometimes the OSX-housed container will barf at start up claiming “port already open” when you’re opening port 0, which is supposed to assign an unused port before opening it, and thus should never barf up “port already open” unless the machine has already exhausted all available ports. This is a complex problem, and many of the steps in the way are better solved with using pre-allocated ports on the invoking docker command-line with -p which is kind of why they designed its common-use-case to use that method in the first place. I would expect that because I’ve been “sold” docker for mac not “docker under a different virtualization engine.” FitNesse tests that run under docker on mac in a virtual box work, but do not work “natively” because FitNesse can not connect to the exposed web interfaces running in the docker container.
Documentation on how to use -net=host under OSX would be great. What documentation I’ve found so far leads me to believe that -net=host should work on mac the way it works on Linux. What’s the advantage of “docker for mac” if it behaves differently than “docker for Linux?”. P doesn’t work like it does in Linux.
For example:%docker run -p 8765:8765 ua-cloud%curl localhost:8765/start Cloud OK%docker run -p 8765:8765 -net=host ua-cloud%curl localhost:8765/start curl: (7) Failed to connect to localhost port 8765: Connection refused Under linux, I can get docker containers to talk to each other and allow me to access exposed URLs. Under docker for mac, it seams I can not. In the Dockerfile for cloud, we have EXPOSE 8765 9090 61666 I’m not sure if that’s equivalent to -p 8765:8765. I assumed “Docker for mac” meant my Docker images that work out of the box in Linux would work in Mac.
If you need Linux on your Mac, run VirtualBox (using Vagrant?) and run Docker inside those VMs. You should do this especially if you need to test your apps on a multi-host setup. You can also run “Docker in Docker” in Docker for Mac, so you can run a swarm of Docker daemons which might be enough of a test environment for your multi-host apps. Within the swarm, you can use Docker networks to isolate your services to only certain user defined networks. I’ve been using Docker for Mac since the public beta has come out, and while it is still beta, it has been a huge improvement over Docker Toolbox using VirtualBox VMs. I don’t think Docker for Mac is intended for deployment of your apps, only so you can test them on your laptop during development.
For this purpose, Docker for Mac is a huge step in the right direction.