Skip to content

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

Description

@Erokos

Windows Version

Microsoft Windows [Version 10.0.26100.3775]

WSL Version

2.3.26.0

Are you using WSL 1 or WSL 2?

  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions