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
Issue:
if i understand your problem correctly:
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.