roadmap icon indicating copy to clipboard operation
roadmap copied to clipboard

Support Host Network (--network host) mode on Docker Desktop for Mac and Windows

Open hexcowboy opened this issue 5 years ago • 73 comments

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

hexcowboy avatar Jun 16 '21 18:06 hexcowboy

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.

Amondale avatar Sep 20 '21 15:09 Amondale

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..?

gramss avatar Mar 12 '22 10:03 gramss

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

zfil avatar Mar 20 '22 14:03 zfil

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.

christophermclellan avatar Mar 30 '22 15:03 christophermclellan

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.

wiredwiz avatar Jun 29 '22 18:06 wiredwiz

Another limitation I've found - not being able to run a local Redis cluster https://redis.io/docs/manual/scaling/#redis-cluster-and-docker

hexcowboy avatar Jul 29 '22 04:07 hexcowboy

Related to https://github.com/docker/desktop-linux/issues/87

ReubenFrankel avatar Oct 24 '22 10:10 ReubenFrankel

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 ! 👍

gramss avatar Nov 27 '22 13:11 gramss

+1 - would be really nice to get this implemented as it works on Linux!

logical-and avatar Jan 06 '23 10:01 logical-and

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 ?

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 ! 👍

Is there any way to get more updates on this ? I think this would be an extremely appreciated feature for mac users

jwoodrow avatar Jan 23 '23 10:01 jwoodrow

Here's the link to the filter to track its progress!

https://github.com/docker/roadmap/projects/1?card_filter_query=network+host

davidthornton avatar Jan 29 '23 06:01 davidthornton

Yes please. Very much please.

dewdrinker19 avatar Feb 11 '23 04:02 dewdrinker19

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?

ghost avatar Feb 11 '23 09:02 ghost

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.

alikhanich avatar Feb 16 '23 07:02 alikhanich

bump. I have several tools that I would love to be able to containerize that need layer2 access.

BlaiseOfGlory avatar Feb 21 '23 16:02 BlaiseOfGlory

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.

ShutdownRepo avatar Feb 23 '23 14:02 ShutdownRepo

https://orbstack.dev/

Website has been registered for only 1 week. How well do you know it?

ghost avatar Feb 23 '23 14:02 ghost

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.

ShutdownRepo avatar Feb 23 '23 14:02 ShutdownRepo

Any update on this? Host networking is a huge enabler for local development of WebRTC apps & games.

reececomo avatar Mar 06 '23 12:03 reececomo

it would be great have this flag for mac and windows in order to run some container against host machine for early testing

jupadev avatar Mar 16 '23 14:03 jupadev