Host networking not working on Docker Desktop in WSL2 with mirrored mode

As the title states, I have a container running on Docker Desktop in WSL2 that should be using host networking but when I check the IP within the container it’s not using the same IP as the host. I’m assuming there’s something that I’ve overlooked and I’m hoping that you guys can help me.

For the configuration, I’ve got a PC with WSL2 Ubuntu running on Win11 that’s configured to mirrored networking. I have confirmed that both the Win11 host and the Ubuntu instance both see the same exact local IPv4 address and only that single address. Within Docker Desktop in Settings > Resources > Network I have “Enable Host networking” checked. The compose yaml is set to network_mode: host and I have confirmed in Docker Desktop under the “Inspect” tab for my container that “HostConfig” > “NetworkMode” is showing as “host”. Everything is on the latest version and I’ve restarted everything multiple times by this point.

However, when I go to the “Exec” tab and run hostname -I I get 3 IPv4 addresses and 2 IPv6 addresses. The IPv4 addresses are 192.168.65.6 192.168.65.3 172.17.0.1. None of those match my host IP. The first 2 are from the default “Docker subnet” specified in Settings > Resources > Network and the 3rd is obviously the Docker IP used for bridge networking.

Where am I going wrong? As far as my configurations go it seems like I should be in host networking, but from within my container it appears as if it might be in bridge networking.

Docker Desktop does not leverage mirrored mode, the “Enable Host Networking” feature will not give you the host ip inside the container. Though it will mirror all received requests from the host to the container, and all outgoing connections from the container to the host. This is implemented on all platforms using vpnkit. From what I remember the mirrored interface exists in the docker desktop distribution, which runs the docker engine in a container, which does not see the mirrored interface.

If you want to use the mirrored interface, for time being your only option is to install and run docker-ce in a WSL2 distribution directly.

You can test it yourself:
This is the system distribution for docker desktop sees:

wsl -d docker-desktop --system ip address

This is what the docker engine inside is able to see:

docker run -it --rm --privileged --pid=host justincormack/nsenter1 /bin/ip address

Thanks so much for the info. Switching to docker-ce inside WSL2 fixed the issue.