I have a fast API service running on windows, I need it there because it is connected to some native old services that only runs on windows right now. I have a node API running on docker-wsl. Is there any way I can do a post request to the windows API?
I’ve tried to connect using the IP instead of localhost but I think because of I’m running from docker it cannot connect.
2
Answers
In windows open a command line, in there type :
ipconfig
There should be properties for an adapter called "vEthernet" (WSL).
This IPV4 is the address you should use instead of localhost from inside WSL, it usually starts with 172 (not sure if that’s always the case though).
There’s a special name you can use in the
add-host
option on yourdocker run
command calledhost-gateway
. That adds a hostname you can use to connect to services running on the docker host.Usually the host name
host.docker.internal
is used, but you can use anything you want.As an example, if your image is called
myimage
, you’d do something likeIf your API is running on port 1234, you’d then connect to it using hostname
host.docker.internal
and port1234
.More info here.