G
G
Gennady S2021-08-03 22:09:34
Docker
Gennady S, 2021-08-03 22:09:34

How to make Windows see the network from WSL2 in host mode?

An interesting feature, the solutions of which have not yet been found (and such a question has arisen on the network more than once, for example ). If the machine is inside WSL2, let's say Ubuntu under Windows, and create a container with an open port, it is accessible from Windows, but if you make the host mode, Windows does not see the created network point-blank. For example, this will open localhost on Windows:

containers:
  nginx:
    image: nginx:latest
    ports:
       - '80'

Well, no:
containers:
  nginx:
    image: nginx:latest
    network_mode: host
    expose:
       - '80'

It seems to be solved by installing Docker inside WSL2, but I have a number of projects on my working machine and I would not want to rebuild everything.

PS You can forward using SSH, you can configure the Hyper-V / WSL2 network interface in bridge mode, you can perform port forwarding every time you start (I could not start it, but they write that it is possible). One thing is not clear why Docker works in closed network mode and open ports, but stops working when the network is opened. Does Docker have its own forwarding mechanisms?

PS It is clear that it is not necessary to rummage around the network, but in one of the old projects wrapped in Docker, it was not possible to solve the connection between containers, where web applications communicate with each other via nginx - constant crashes to SSL, and the corresponding refactoring is not possible at this stage. And if on a working machine with Linux everything is in order, then on Windows you have to work inside WSL2.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gennady S, 2021-08-23
@gscraft

This problem does not have an adequate solution. Docker for Windows has a special implementation, its own network, and host mode means that the application will not run on the WSL2/Windows network, but on Docker's own network. Whereas opening ports creates tunnels for WSL2 and Windows networks. The only way to get this to work is to manually tunnel each time you start containers, which is hardly an easy thing to do because, again, according to the documentation "This interface is actually within the virtual machine".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question