Search code examples
javadockerjmx

Cannot connect jmx to java app running in docker on remote host


Assuming I have a server in my local network with ip 192.168.100.10. There is docker container running in it with java application. Now i want to connect to this java application with VisualVM from my computer which has ip address 192.168.100.20. I thought I had everything configured properly but it still does not work.

I have passed these JVM options:

   -Dcom.sun.management.jmxremote"
   -Dcom.sun.management.jmxremote.port=9010"
   -Dcom.sun.management.jmxremote.authenticate=false"
   -Dcom.sun.management.jmxremote.ssl=false"
   -Dcom.sun.management.jmxremote.local.only=false"
   -Dcom.sun.management.jmxremote.rmi.port=9010"
   -Djava.rmi.server.hostname=192.168.100.10"

Then I have exposed port 9010 in Dockerfile:

EXPOSE 9010

Then added this port to docker-compose:

    ports:
      - "9010:9010"

I am trying to connect to remote host with JConsole or VisualVM from my local machine. In "Remote Process" input in JConsole I put "192.168.100.10:9010" but connection fails with error: "The connection to 192.168.100.10:9010 did not succeed. Would you like to try again?"

What am I doing wrong?


Solution

  • The solution above is sufficient and working. I've been using env variable to set port number which was not working properly.