Macos - how enable a http client from within a docker container to hit the host's localhost endpoint?

I have a situation where I can run the app “natively”. The app makes several outgoing requests using a http client. When operating from within a docker container

  • the running image can reach external endpoints but to the degree “external” means outside the docker image
  • the running image fails to reach http://localhost:xxxx

If memory serves working with kind on macos (a docker dependent kubernetes setup), I learned that “extra” effort was required to make this type of connection. In this case, it requires creating an explicit capacity to forward localhost requests to the host… something that a linux-based host does not require.

Has anyone had this experience and familiar with how to augment my local-dev setup accordingly?


Docker supports host.docker.internal. When the running image points to this “domain”, the docker container figures out how to hit the host’s localhost. On the surface that should be the solution.

However, in my playing with it I get the following. I have a couple of local services with which I get different outcomes. To be clear, there is a third service that is the focus of this post that needs to hit each of these services. This third service is configured with the following “hit and miss” settings :))

These are set in a docker-compose.yml file (as published and target ports).

Changing the first service to use 3000 for both target and published fails both using localhost and the new setting. So it’s not about matching ports. In fact, the only way I got it go was using different ports and the new setting.

What calls to docker might be useful to better understand what’s going on? (if only to anticipate and better understand the networking)

Here is a link to the docker documentation on the subject; I’m still processing it.