I’m running Docker Desktop (Windows) with docker version 20.10.14
I’m trying to run a daemon process on a container (Linux) and have my host machine (Windows) communicate with it by sending a JSON message to the published port.
WSL2 is known to bind published ports to localhost host only (=not reachable by lan ip, a workarround is possible though). This is why I suggest 127.0.0.1.
I should have asked more precisly. I was currious just about the backend.
To narrow down the problem, personaly I would exec into the container and check if the container port is reachable within the container, if tools are missing in the container, you can hook another container into the network namespace of the container and use it for testing, e.g. docker run -it --net container:<container_name> nicolaka/netshoot (localhost and bridge network ip will be same for both containers). If it’s not working, its something in the container.
Once its verified, I would open a shell to the wsl distribution wsl -d docker-desktop and repeat the tests, this time with the published host port. If it’s not working, its probably soemthing with docker.
Once the test inside the wsl distribution is positive, we know the issue is high likely between the host and the wsl2 distro. Afterall all wsl2 distro still run in a lightweight vm with its own ip. Ports bound inside a wsl2 distro should be reachable from the Windows host, except when a firewall restricts it (which usualy is not the case on private maschines, but companies tend to tighted the security with endpoint protection of some sorts).
So I was able to communicate with the daemon running in the container by hooking another container in the same network namespace.
The second test in terms of doing the same thing as before but in the wsl2 shell also works.
I’ve update my firewall settings to allow inbound/outbound connections on port 8888 on my machine but still cannot communicate with my container from my windows host (without using another container).