WSL icon indicating copy to clipboard operation
WSL copied to clipboard

Setting the network mode to host for a docker container doesn't reflect on the WSL2 instance or windows host

Open Erokos opened this issue 7 months ago • 1 comments

Windows Version

Microsoft Windows [Version 10.0.26100.4061]

WSL Version

2.3.26.0

Are you using WSL 1 or WSL 2?

  • [x] WSL 2
  • [ ] WSL 1

Kernel Version

5.15.167.4-1

Distro Version

Ubuntu 24.04

Other Software

Docker Desktop Current version: 4.39.0 (184744)

Repro Steps

Install Docker Desktop on Windows 11 and make it use WSL2 as its backend. Run openvpn in a docker container within wsl2 distro of your choice (Ubuntu 24.04 is in my example), and set the network mode for the container to host. Here's an example of a compose file used to run the container with the openvpn client inside it. Routes will be configured within the container but not on the WSL2 instance and resources will only be reachable from within container.

services:

  eu:
    image: openvpn-ubuntu22
    container_name: eu-openvpn
    restart: always
    #privileged: true
    environment:
      - openvpn_config=openvpn-eu.ovpn
      - auth_file=eu-auth.txt
    #volumes:
    #  - ./openvpn-configs/:/etc/openvpn/
    devices:
      - "/dev/net/tun:/dev/net/tun"
    cap_add:
      - NET_ADMIN
      - SYS_ADMIN
      - DAC_READ_SEARCH
    network_mode: "host"

Expected Behavior

When using the network mode set to host, the networking settings should at least reflect on the WSL2 instance and routes should be added correctly. This is the behavior observed on a pure linux system.

Actual Behavior

Within the container routes are added and resources are reachable from within the container where vpn is running but not from WSL2 or the Windows host.

Diagnostic Logs

WslLogs-2025-05-11_10-56-02.zip

Erokos avatar May 22 '25 08:05 Erokos

Diagnostic information
Detected appx version: 2.3.26.0

github-actions[bot] avatar May 22 '25 08:05 github-actions[bot]

This is the expected behavior. Docker desktop changes shouldn't affect WSL.

Closing since this is by design.

OneBlue avatar May 27 '25 21:05 OneBlue

Sorry, but how is this behavior expected? There are no Docker Desktop changes, just setting the container network mode, of a specific container, to host which should affect the host system, in this case WSL2 Ubuntu 24. Are you telling me that if I had docker installed in WSL2 itself and not via Docker Desktop that it would behave as expected on any other linux system? Can you please provide more info?

Erokos avatar May 31 '25 12:05 Erokos