I am trying to remotely monitor a JVM running in docker. The configuration looks like this:
machine 1: runs a JVM (in my case, running kafka) in docker on
To add some additional insights, I had some Docker port mappings in use, and none of the previous answers worked directly for me. After investigation, I found the answer here: How to connect with JMX from host to Docker container in Docker machine? to provide the required insights.
This is what I believe happens:
I set up JMX as suggested in other answers here:
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=1098
-Dcom.sun.management.jmxremote.rmi.port=1098
-Djava.rmi.server.hostname=localhost
-Dcom.sun.management.jmxremote.local.only=false
Program flow:
host:docker
port mapping of 1099:1098.localhost:1098
localhost:1098
Docker:1098
. Instead of localhost:1098
, JMX should tell JConsole to read monitoring information from localhost:1099
, since 1099 was the port mapped from host to 1098 inside Docker container.As a fix, I changed my host:docker
port mapping from 1099:1098
to 1098:1098
. Now, JMX still tells JConsole to connect to localhost:1098
for monitoring information. But now it works since the outside port is the same as advertised by JMX inside Docker.
I expect the same applies also for SSH tunnels and similar scenarios. You have to match what you configure JMX to advertise and what JConsole sees as the address space on the host where you run it.
Maybe it is possible to play a bit with the jmxremote.port
, jmxremove.rmi.port
, and hostname
attributes to make this work using different port mappings. But I had the opportunity to use the same ports, so using them simplified it, and this works (for me).