I'm using docker containers for my development on a Mac host. The containers are Linux systems. I currently have two seemingly contradictory development needs from this container:
- In order for my project's tests to run properly in my containers, I need to run the containers in host networking mode (the
--network=host
todocker run
). - I also build the project's docs in the container and would like to access the simple Python HTML doc server I run in the container from a browser on my Mac host. This works just fine if I map a port to the container via port publishing (the
-p
argument todocker run
).
My problem is, as advertised on that host networking page I linked to, port mapping does not work when host networking is used:
Note: Given that the container does not have its own IP-address when using host mode networking, port-mapping does not take effect, and the -p, --publish, -P, and --publish-all option are ignored, producing a warning instead:
So, as far as I currently know, I can only do one or the other:
- Run the container in host networking mode so the tests can run. But then I cannot see my built docs rendered via a browser on my host.
- Or don't run in host networking mode and use the port publishing feature to see the docs from my Mac host. But then I cannot run the tests.
I get the impression this isn't a problem for Linux hosts as, in that case, I could simply access the container's listening ports from my Mac host since the container's network is the same as my host. But for Macs, the container runs in a VM and accessing that service isn't so easy.
My question is: how do I access the listening ports of a container from my Mac host when using host networking mode?
Note: if this isn't possible and you know it, please post that as an answer. Knowing that I cannot do it would be helpful for me so I can adjust my expectations.
--network=host
on a Mac.