skip to Main Content

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


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

    Login or Signup to reply.
  2. There’s a special name you can use in the add-host option on your docker run command called host-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 like

    docker run --add-host=host.docker.internal:host-gateway -d myimage
    

    If your API is running on port 1234, you’d then connect to it using hostname host.docker.internal and port 1234.

    More info here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search