I’ve tried searching for this problem elsewhere, but can’t find anything describing this scenario. Everything seems to be about connecting from Windows to WSL, or Windows to a Docker container, but what I want is from a docker container to WSL.
I’m using Docker Desktop for Windows, on Windows 11 Pro (10.0.26100).
Docker Desktop is installed from MS store (v4.41.0).
FWIW my WSL distribution is Debian 11.11, but I tried this with an Ubuntu 24 dist, and same issue.
For development, I need to connect to a remote service API that is locked down by IP. I can make HTTPS connections to the remote service by creating an SSH forward proxy tunnel from WSL, with a command like:
ssh -N -L 0.0.0.0:8001:www.example.com:443 server.with.access -f
From within my WSL distribution I can connect to the remote service with telnet 127.0.0.1 8001
, and also with the WSL specific IP (in the 172.x.x.x range, let’s say 172.1.2.3).
Using Postman in Windows, I can connect to the remote service and perform API requests using the WSL IP and the forward port.
The one thing I can’t do is connect to the remote service from a docker container, which means I can’t test the code/application against the remote service.
I’ve tried using the WSL IP address (times out trying to connect), the host.docker.internal
address (connection refused), and a variety of other IPs based on the address range and some guess that it might be doing some internal routing.
The thing is, I exported the ext4 disk and imported it on my home PC (Windows Home), and under the same circumstances I was able to successfully connect to the remote service using the WSL IP (e.g. 172.3.2.1) and the forward port, so I know that this can work.
Is anyone familiar with Docker and WSL, and maybe Docker networking, that might have some suggestions as to what the issue might be?