Repository navigation
Support Host Network (--network host) mode on Docker Desktop for Mac and Windows #238
Description
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
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsConsidering
Activity
Amondale commentedon Sep 20, 2021
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.
gramss commentedon Mar 12, 2022
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..?
zfil commentedon Mar 20, 2022
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
christophermclellan commentedon Mar 30, 2022
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.
wiredwiz commentedon Jun 29, 2022
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.
hexcowboy commentedon Jul 29, 2022
Another limitation I've found - not being able to run a local Redis cluster https://redis.io/docs/manual/scaling/#redis-cluster-and-docker
ReubenFrankel commentedon Oct 24, 2022
Related to docker/desktop-linux#87
gramss commentedon Nov 27, 2022
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 ! 👍
logical-and commentedon Jan 6, 2023
+1 - would be really nice to get this implemented as it works on Linux!
jwoodrow commentedon Jan 23, 2023
Is there any way to get more updates on this ? I think this would be an extremely appreciated feature for mac users
davidthornton commentedon Jan 29, 2023
Here's the link to the filter to track its progress!
https://github.com/docker/roadmap/projects/1?card_filter_query=network+host
dewdrinker19 commentedon Feb 11, 2023
Yes please. Very much please.
51 remaining items
akerouanton commentedon Apr 25, 2024
@vadimen I'm not super familiar with Windows Containers networking. I think it's worth looking for a similar issue or asking on https://github.com/microsoft/Windows-Containers.
Nemesis7 commentedon Apr 26, 2024
@akerouanton By default it's port 10443, plus there one port for HomeKit which is variable and there is the mDNS port i.e. 5353, but shouldn't this recent release allow any container with
network_mode: hostto be reachable vialocalhost? For Scrypted I can create a new issue, but I think reachability vialocalhostis related to this thread, no ?akerouanton commentedon Apr 29, 2024
@Nemesis7 It's definitely related but it'd be better to have a proper bug report.
AndreKR commentedon May 18, 2024
Hm, am I missing something?
I'm running 4.30.0:
Under "Features in development" I enabled "Enable host networking":
(For unknown reasons that checkbox only became enabled when I logged into an account, it's unclear to me how networking and login are related.)
If I now run netcat in listen mode in a container:
I am unable to connect to that from outside the container:
But if I exec into the container and try the connection from there, it works:
That should work from the host as well, or not?
tangledhelix commentedon May 18, 2024
Using
-land-ptogether is an error. Fromnc(1):Also, when using listener mode the port is random:
If you run a listener like this, and then try to connect to it using localhost on the outer system, it still won't work, because you can see it is bound to
[::]which is the IPv6 stack. The--net=hostparameter will only bind to IPv4, so the last piece of the puzzle is to specify an IPv4 address to bind to...And after this, connecting to localhost on the outer host, using the port in the message (59271 in this example) should work. I tested this on Mac, although I see you're using Windows. I would hope it works the same, but YMMV.
AndreKR commentedon May 18, 2024
What image are you using for your container? The netcat syntax you're using is for BSD netcat, for GNU and Busybox netcat my syntax should be ok.
I tried installing BSD netcat in my Alpine container but I couldn't get it to work with your commands:
I tried specifying a local IPv4 address to rule out the IPv6 issue you mention with
nc -l -p 1234 -s 0.0.0.0andnc -l -p 1234 -s 127.0.0.1but the netcat is still not reachable from the host.tangledhelix commentedon May 18, 2024
Based on your screenshot, to replicate your environment, I used alpine:latest.
I will admit I probably used the manpage from macOS (which would have the BSD version), not realizing the disparity between it and GNU/Linux. But the behavior I tested and pasted output from came from
alpine:latest:I see now that your syntax works and has the right port (which it clarifies with
-v). But, it binds to IPv6 only, which leads back to my observation about needing to use IPv4:If you bind to the IPv4 stack it then allows connection from the outside host:
AndreKR commentedon May 18, 2024
Using your command line doesn't work for me:
tangledhelix commentedon May 18, 2024
Ah, sorry to see that. Unfortunately I have no explanation for it. I would guess it is a difference in the Mac vs. Windows environment (either the network stack, or the way Docker Desktop works with the host OS, or both). I don't have any Windows machines around here to test it.
s13n commentedon Aug 5, 2024
It doesn't work with me. I'm using v4.33.0 on Windows 11, and have enabled the feature after signing in. Alas,
docker infodoesn't show the host network mode as available, and starting a container with--net=hostthrows an error.Network: ics internal l2bridge l2tunnel nat null overlay private transparentAm I doing something wrong? Do I have to create the host network somehow?
akerouanton commentedon Aug 5, 2024
@s13n This feature isn't compatible with Windows containers. It's meant to be used with Linux containers, on both macOS and Windows.
s13n commentedon Aug 6, 2024
@akerouanton Thanks! That wasn't clear to me, and the explanatory text near the tick box in the settings dialog doesn't mention it. Maybe it would be an idea to disable the choice when Docker Desktop is in Windows container mode.
akerouanton commentedon Aug 6, 2024
@s13n Thanks for reporting! This should be fixed in the next release (4.34).