Access tomcat running in docker container by JMX
Here's the flags I've successfully used for monitoring my ZooKeeper container via JMX:
-Dcom.sun.management.jmxremote-Dcom.sun.management.jmxremote.local.only=false-Dcom.sun.management.jmxremote.authenticate=false-Dcom.sun.management.jmxremote.port=9010-Dcom.sun.management.jmxremote.rmi.port=9010-Djava.rmi.server.hostname=0.0.0.0-Dcom.sun.management.jmxremote.ssl=false
So the difference would be this entry -Dcom.sun.management.jmxremote.rmi.port
which is fix the RMI port to be the same as JMX port.
With this I can just docker run -p 9010:9010 ...
and everything is fine for me.
This does not work when you run that container in Docker machine - in VirtualBox. I am not sure what kind of address I should add to java.rmi.server.hostname because when I add there external IP of the Docker container I am connecting from my host, it does not work. So basically situation is like HOST ---> (MACHINE --- CONTAINER) and I can not reach it from HOST to CONTAINER.
I'm not sure if it's necessary but I would recommend adding this to your additional options -Djgroups.bind_addr=172.17.0.16
. Also I'm pretty sure that this kind of options should probably go to CATALINA_OPTS and not JAVA_OPTS but that shouldn't make a difference. Another thing that I noticed is that the rmi server host name you defined is different than the one in the JMXServiceURL constructor. I'm no docker expert but shouldn't this be identical?