Cannot access container through mapped port on container, closed by foreign host

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.

My docker-compose.yml looks something like this:

version: "3.9"  # optional since v1.27.0


    image: image_name
    command: /opt/ssi/bin/daemon -p 8888
       - 8888
      - "8888:8888"

and I run docker compose up for this service.

The daemon launches with a parameter specifying which port to listen for JSON strings (8888 in this case).

I tried to use Putty to send a JSON string to (Raw) port 8888, but when I attempt to connect I get:


I tried to run telnet to try and connect to the published port as well:

xm97wa@CAMIS2-L3CQ77G3:~$ telnet 8888
Connected to
Escape character is '^]'.
Connection closed by foreign host.

I’m not sure what else I need to do

try telnet 8888.

No luck, I get the same response

Just to be sure: you are running DDfW with WSL2?

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

Yes I am using Docker Desktop for Windows with the WSL2 backend

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).

Please report back which of the tests succeeded.

Sorry for the delay.

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).