I want to create a docker network with a bridge driver for my linux docker container, that runs on a windows host.
The idea is to create a subnet that has the same network range as my WSL network on the host IPv4 Address. : 172.31.16.1. The purpose is to be able to run a UDP client/server (where the server shall run on the linux container and the client on the host).
My setup:
Host: Windows 10 (WSL2)
ubuntu:latest container running on docker desktop
Steps i have takes sofare:
Created a network: docker network create --driver=bridge --subnet=172.31.16.1/24--ip-range=172.31.16.0/24 br0
Connect the network (br0) to my container: docker network connect br0 <container>
this creates a network on the container named eth0, however I am not able to ping from the host in to the container, but can ping my local host ip address from the container , i.e.:
If you create the same network inside WSL, you actually breake the network. Never overlap Docker network with your host network (WSL in this case)
WSL network is not static. When you reboot Windows, WSL can (and probably will) get a new network in a different subnet and with different IP address.
I don’t know any way to make WSL network static, so I don’t think you could use MacVLAN either. WSL is not designed for that. I actually stopped using WSL2 for Docker when I updated Windows 10 to Windows 11, because the update forced me to delete VirtualBox which was responsible for creating a static network range that could be used by WSL, so WSL could not get the same or (overlapping) IP range as Docker. I could change Docker’s default configuration to use a different range, but I had Linux machines, so I didn’t do it.
On the other hand, I noticed that you use Docker Desktop for Windows, which somehow able to create a static subnet. I couldn’t figure out how. But that subnet is something like 192.168.65.0/24 by default not 172.31.16.0/24. Have I misunderstood you? Even if I have, I don’t think you could do what you want with WSL. At least not permanently
Hi thank you for your response.
The main reason I selected WSL network was due to my, perhaps naive thought, that the subsystem (linux) could communicate with the Linux container without any problem. I am probably wrong here. My aim here is to understand and learn how docker networks work, perhaps in building a network where I could have a communication link between the container and the windows host eg. a simple client-server over UDP. Perhaps stating by an ICMP (ping).
What I could read from google so far, is that I am not able to use the “host” option as the driver as it won’t work on windows or mac host…but only works for host linux systems.
So am I completely wrong in my understanding of the docker network here? or is there any solution?
thanks in advance
It would be an ideal case, and it is not entirely impossible, but you need to configure Docker to use another network, not the default. Docker uses subnets from 172.17.0.0 but WSL2 does the same. I guess this is why Docker Desktop supports setting a static IP address in its own way. If I want to do it withuout the Desktop, I would have to do some research and configure it. I would afraid of loosing my config whenever I get a Windows upgrade, so WSL2 is not worth that much to me. It is a very good tool when you don’t want to or can’t run a virtual machine or use a physical machine, but you cannot do everything so easily as you could do with a “real” virtual machine where you are in total control.
If you are really using Docker Desktop as the category of this topic indicates, that is an other useful tool for certain people and for certain tasks. Not for everything and not for everyone. It makes easier to use your NVIDIA GPU, gives you a way to start a dev environment based on containers and also helps you to switch between Linux containers and Windows containers, or run a small single-node Kubernetes “cluster”. You can also browse your images and containers but this is what I don’t consider as useful as the other features, because I prefer to use the terminal.
On the other hand, you get an other layer on top of WSL, so you have more restrictions, but you can use the docker client on your windows host. It would be possible without Docker Desktop, if you know how to configure Docker on the server and the client on the host to do it.
This is not completely true. You CAN use the --net host option, but since Docker runs inside a virtual / WSL2 machine, host would mean the virtual machine and not your Windows or Mac host. This option is still useful when you want to debug the network inside the host. For example if you want to know what interfaces are available in the VM. So the reason you can’t use --net host the usual way is not the fact that you have a Windows or Mac host, but the virtualization, which is required for Linux containers on these platforms. If you run a virtual machine on Linux to run Docker daemon inside that and use Docker client on your Linux host, that would work the same way.