- 1 year ago
running network mode “host” on windows 10 with wsl2 and docker
Running Docker containers in network mode "host" on Windows 10 with WSL 2 requires some additional configuration steps. By default, Docker for Windows does not support the "host" networking mode on Windows. However, you can use the following workaround to achieve a similar effect:
Ensure that you have Docker Desktop installed and properly configured with WSL 2 integration. If you haven't set up Docker with WSL 2, follow the official Docker documentation to enable WSL 2 backend (https://docs.docker.com/docker-for-windows/wsl/).
Open the WSL 2 distribution (e.g., Ubuntu) that you are using.
Inside the WSL 2 distribution, install Docker if you haven't already. Refer to the Docker documentation for instructions specific to your Linux distribution (e.g., Ubuntu: https://docs.docker.com/engine/install/ubuntu/).
Start Docker inside the WSL 2 distribution:
bashsudo service docker start
Set the Docker daemon to use the WSL 2 backend by configuring the
DOCKER_HOST
environment variable:bashexport DOCKER_HOST=tcp://localhost:2375
Verify that Docker is running inside the WSL 2 distribution and accessible through the WSL 2 TCP endpoint:
bashdocker version
Now, you can run Docker containers in "host" networking mode inside the WSL 2 distribution:
bashdocker run --network host <image_name>
By configuring Docker to run inside the WSL 2 distribution and using the WSL 2 TCP endpoint, you can effectively achieve a similar networking behavior as the "host" mode on Linux.
Please note that this workaround involves running Docker inside the WSL 2 distribution, and the Docker daemon is not directly running on Windows. Therefore, you won't be able to access Windows-specific network interfaces or services directly from containers in this mode.