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
2
Answers
Pass
--net=host
todocker run
.This will share the host’s IP address and networking stack. Basically, that means the application will run without Docker imposing any restrictions on network access.
Source
N.B.: The
-p
port mapping flag is unsupported with--net=host
. Your Promethesus container’s port 9090 will act as if it’s always mapped to the same port 9090 on the host.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 usehost.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.