skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search