-1

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

1

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Docker only supports the host.docker.internal hostname by default on some platforms, so to be safe, you should add --add-host host.docker.internal=host-gateway to your docker run command. More info here
-1

do not want to dockerize my springboot application

Then you could run Prometheus outside of Docker. That way, scraping of localhost work work as expected

Comments

-3

Pass --net=host to docker 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.

If you use the host network mode for a container, that container's network stack isn't isolated from the Docker host (the container shares the host's networking namespace), and the container doesn't get its own IP-address allocated. For instance, if you run a container which binds to port 80 and you use host networking, the container's application is available on port 80 on the host's IP address.

This feature works in both directions. This means you can access a server that is running in a container from your host and you can access servers running on your host from any container that is started with host networking enabled. TCP as well as UDP are supported as communication protocols.

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.

2 Comments

This doesn't work on Docker Desktop or other VM-based setups. It generally disables Docker's networking layer entirely and it usually isn't a best practice.
@DavidMaze "Host networking is also supported on Docker Desktop version 4.29 and later for Mac, Windows, and Linux as a beta feature." docs.docker.com/network/drivers/host/#docker-desktop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.