Search code examples
dockerdocker-network

How to curl to host from docker container


I'm trying to setup an api gateway using docker container on my machine.

The api container is map to port 8000 and run on a bridge network but the api is running directly on my machine without a container on port 19108 .

What I'm trying to archive is when a HTTP request hit the endpoint /order on the port 8000 it will make another HTTP request to the port 19108 and return the response which was received but can't seem to find a way to make it work since i don't know the host machine ip.

I've tried using host.docker.internal, the ping command returns response but the curl just return HTTP Error 400. The request hostname is invalid.

Are there any workarounds or i should just use the host network instead?


Solution

  • If you need to do that, you can set the container in network mode host.

    docker run --network host myapp
    

    Note, that you cant map the ports now anymore, and the container app will be accessible as if it were running on the host system itself.