Support Host Network (--network host) mode on Docker Desktop for Mac and Windows
Tell us about your request
Right now, docker run --network host <image> is only available to Linux docker hosts. From the official documentation:
The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.
Which service(s) is this request for?
Docker Desktop for Mac, Docker Desktop for Windows
Tell us about the problem you're trying to solve. What are you trying to do, and why is it hard?
Making a docker container with dynamic port mappings is not possible right now.
For example, a container that allows a user to accept connections on arbitrary ports through a netcat listener. During a network penetration test, the user may be testing outbound firewall rules and needs to dynamically accept connections on different ports in the container, eg 53, 80, 443, 1337, 9001, or any other arbitary port. The user will not know these ports before starting the container, so it's not possible for the user to run the container with docker run -p <ports> <image>.
With docker run --network=host, this could be accomplished by just using the same network schema as localhost.
Are you currently working around the issue?
The "best" workaround I know of would to add an EXPOSE 1-1000 in the Dockerfile and run the container with docker run -P <image>, which is very slow and does still limits the range of open ports. Using the full port range of EXPOSE 1-65535 hangs my terminal, so I don't know how effective it is.
The -P flag is documented here: https://docs.docker.com/network/links/#connect-using-network-port-mapping
This is not a sustainable workaround.
Additional context
- https://stackoverflow.com/questions/49323225/expose-all-ports-for-a-docker-image/49323975
- https://stackoverflow.com/questions/54165483/docker-alternative-to-network-host-on-macos-and-windows
Although documentation stats not supported on any O/S but Linux, it also doesn't seem to work correctly (although it doesn't throw error) on Linux flavors on WSL2. The swarm configurations likewise don't function as they do in "bare metal" Linux, which can make for a ton of confusion in the docs.
There is a large and growing population of Mac/Windows users that are not fully supported by the extant documentation, and issues like this (many other networking issues exist on those platforms too).
I plan to follow this thread closely, and would welcome the chance to help refine docs so they apply across the board, or exceptions are noted where they exist.
What is basically needed to make this work? Where would one need to start looking to make this work on MacOS? Any basic information on how to start that would be much appreciated. I think technically this should be doable, also from the community. It's currently just not on the roadmap..?
Having this supported could maybe help with the horrible network performance I see on macos docker ...
This makes for instance using postgres in a container very painful. Running our test suite using a postgres in a container and with docker 4.6: virtualization.framework: 16min hypervisor.framework: 10min locally installed postgres: 3min
Hi - thanks for this issue and sorry for the delayed reply. We'll do some scoping on this and circle back on this thread shortly.
This is certainly a feature I would love to see support for. lacking host network support makes it impossible for me to run services that need to be network aware on anything other than linux, since otherwise they only see the network bridge.
Another limitation I've found - not being able to run a local Redis cluster https://redis.io/docs/manual/scaling/#redis-cluster-and-docker
Related to https://github.com/docker/desktop-linux/issues/87
Now with the new release 4.14.0 of Docker Desktop on Mac utilizing the Apple Virtualization Framework, it should be possible to add another network adapter featuring the bridged network aka. network_mode = host ?
https://developer.apple.com/documentation/virtualization/vzvirtualmachineconfiguration/3656724-networkdevices
Is this a big challenge? Can somebody point out the hypervisor configuration for the Apple Virtualization Framework here? :)
Also thanks for putting it in the "Considering" space of the docker-roadmap ! 👍
+1 - would be really nice to get this implemented as it works on Linux!
Now with the new release 4.14.0 of Docker Desktop on Mac utilizing the Apple Virtualization Framework, it should be possible to add another network adapter featuring the bridged network aka. network_mode = host ?
Is this a big challenge? Can somebody point out the hypervisor configuration for the Apple Virtualization Framework here? :)
Also thanks for putting it in the "Considering" space of the docker-roadmap ! 👍
Is there any way to get more updates on this ? I think this would be an extremely appreciated feature for mac users
Here's the link to the filter to track its progress!
https://github.com/docker/roadmap/projects/1?card_filter_query=network+host
Yes please. Very much please.
Here's the link to the filter to track its progress!
https://github.com/docker/roadmap/projects/1?card_filter_query=network+host
It doesn't seem to be getting traction or is it too early to tell?
I've been waiting for 5 years for that. Can you please do it? If the security is main concern please disable this feature by default.
bump. I have several tools that I would love to be able to containerize that need layer2 access.
For everyone's bummed about this lack, the solution may very well be to switch to a more active project 🤷 It's been five years. For instance, https://orbstack.dev/, while not open-source, seems very promising and already supporting the --network=host mode (among other things). I'm amazed to see independent projects like this one surpass Docker Desktop (for mac in this case) performance and feature-wise.
https://orbstack.dev/
Website has been registered for only 1 week. How well do you know it?
https://orbstack.dev/
Website has been registered for only 1 week. How well do you know it?
Not well myself, but I work with 2 people that tested it and that raised excellent feedback.
Any update on this? Host networking is a huge enabler for local development of WebRTC apps & games.
it would be great have this flag for mac and windows in order to run some container against host machine for early testing