1

I'm pretty new to Docker Ecosystem and I have the following question

Is it possible to get the HOST'S IP ADDRESS from docker compose in the newer versions of Docker (I'm on a Mac) - I have searched and I see there isn't an easy way but it seems the answers are old, so I'm not sure if with the newer versions this is possible.

I have a container with a React APP that connects to an API currently on my local machine. If I set the React's API baseURL to http://localhost/ it works fine but If I access the React App from another computer in my network it doesn't connect. So instead of using http://localhost/ I was wondering if its possible to set it to the Host's IP Address dynamically instead of hardcoding it. I was thinking of using and ENV variable to set the API's base URL.

Carlos Sosa
  • 445
  • 1
  • 5
  • 19
  • If you're using the Docker Desktop application, the special host name `host.docker.internal` points there without any special setup. That won't necessarily help your React application, though, since it runs outside of Docker. – David Maze Oct 13 '22 at 20:24
  • 1
    (You can also host `host.docker.internal` under Linux, even if you're not using Docker Desktop; see e.g. https://stackoverflow.com/a/62431165/147356) – larsks Oct 13 '22 at 20:46
  • Thanks. I tried host.docker.internal but since its a React App that runs in the browser and not inside of docker it does not work – Carlos Sosa Oct 13 '22 at 23:15

0 Answers0