Connectivity Issues with Docker Container on WSL

Hello everyone,

I’m experiencing some connectivity issues with a Docker container running on Windows Subsystem for Linux (WSL) and would appreciate any insights or solutions.

Problem Description

I have a Docker container named tys24 that is running a Java application, which is configured to listen on port 7090. The setup is as follows:

  • The container can be accessed via localhost:7090 from within WSL and from the container’s IP address (172.22.0.2) without issues.
  • However, when I try to access the same application from the Windows host using 192.168.0.180:7090, I receive a “Connection refused” error.

Network Configuration

Here are some key points regarding my network setup:

  • The container is connected to a custom Docker network, which is configured with the subnet 172.22.0.0/16.
  • The output of docker port tys24 shows that port 7090 is mapped to 0.0.0.0:7090 and [::]:7090, indicating it should be accessible externally.
  • I have tried adding a port proxy using netsh to forward traffic from 192.168.0.180:7090 to localhost:7090, but it hasn’t resolved the issue.

Commands and Outputs

  1. Docker Network Inspection:
    Run the command docker network inspect custom_network.
  2. Port Proxy Configuration:
    Run the command netsh interface portproxy show all.
  3. Container Listening Ports:
    Inside the container, run the command docker exec -it tys24 netstat -tuln.
    The output shows that the application is listening on ::7090 (IPv6), but not explicitly on the IPv4 address.

Steps Taken

  • Verified that the Java application listens on all interfaces by setting server.address=0.0.0.0.
  • Checked Windows Firewall settings and ensured the necessary ports are allowed.
  • Restarted WSL and Docker multiple times.
  • Attempted to create a new Docker network to see if that would resolve the issue.

Questions

  1. Has anyone encountered a similar issue with Docker on WSL?
  2. Are there any specific configurations that I might be missing to allow external access to the container?
  3. Would using a reverse proxy or different networking configurations help in this situation?

Thank you for your help!

I hope someone will correct me if I’m wrong, because I’m not sure about how up to date I am about WSL, but based on a tutorial I made in 2021, the auomatic port forwarding from the host works only for localhost and not for your LAN IP. I had to forward the port using netsh.

netsh interface portproxy add v4tov4 listenaddress=<LAN_IP> listenport=<LAN_PORT> connectaddress=<WSL_IP> connectport=<WSL_PORT>

Since the WSL IP could change, you could use 127.0.0.1 as target instead of the WSL IP and the request will be forwarded to your application. Although I’m not sure what you would see as a client IP when forwarding the IP from the host IP to 127.0.0.1.