

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”. 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. (Otherwise, it can’t track the opened ports.) 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.ĭocker was designed with the intent that -p is the way things will work. Is the behavior inconsistent? Yes, it is. 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?

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.
#Docker network mode host mac#
The invoking agent on the Mac knows exactly which port needs to be redirected and how.

It is not docker running on the Linux machine that is instigating this port opening. 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. I also tried this with pinata set network nat and pinata set network hostnet– neither works. The service doesn’t need to be python3- any native app that binds to localhost will work.

I also tried every address known to the container: $ docker run -it -rm -net=host buildpack-deps:curl sh -c 'for ip in $(ip addr | grep "inet " | cut -d " " -f 6 | cut -d "/" -f 1) do curl $:8000 done'Ĭurl: (7) Failed to connect to 127.0.0.1 port 8000: Connection refusedĬurl: (7) Failed to connect to 192.168.65.2 port 8000: Connection refusedĬurl: (7) Failed to connect to 172.19.0.1 port 8000: Connection refusedĬurl: (7) Failed to connect to 172.18.0.1 port 8000: Connection refusedĬurl: (7) Failed to connect to 172.17.0.1 port 8000: Connection refused On OSX, the output is simply curl: (7) Failed to connect to 127.0.0.1 port 8000: Connection refused
