spring-bootdockerdocker-network

Making docker application talk to application running locally on host machine at localhost ip


I have Prometheus running at port 9090 in docker container and the port is mapped to host port 9090. I can access Prometheus. I have a spring boot application running natively on localhost on the Mac laptop at port 8085. Prometheus is unable to access the end point localhost:8085/actuator/prometheus. Even if I try to map the port when starting container it won't help in this case.

What is the way to make this work? I do not want to dockerize my springboot application


Solution

  • Issue:

    if i understand your problem correctly:

    1. You have Prometheus running inside docker container.
    2. From Prometheus, you are not able to access ep: localhost:8085/actuator/prometheus

    Reason:

    localhost inside container would refer to container itself, Hence it's not able to access the endpoint running on your host machine.

    Solution

    instead of localhost, you need to use host.docker.internal. So your url should look like this: host.docker.internal:8085/actuator/prometheus

    If this solves the issue, then mark Answer as accepted.