Connecting with JMX using Docker for Mac

Viewed 1304

I'm struggling with setting up a JMX connection to Tomcat running in a Docker container using Docker for Mac. I think I understand the basics, and have a setenv.sh in the tomcat/bin directory looking like this:

CATALINA_OPTS="-Dcom.sun.management.jmxremote=true\
 -Dcom.sun.management.jmxremote.local.only=false\
 -Dcom.sun.management.jmxremote.authenticate=false\
 -Dcom.sun.management.jmxremote.ssl=false\
 -Djava.rmi.server.hostname=185.83.15.228\
 -Dcom.sun.management.jmxremote.port=9999\
 -Dcom.sun.management.jmxremote.rmi.port=9999"

I think the problematic part might be the java.rmi.server.hostname property. I've set this to the IP of the host machine, but I've also tried other obvious things. I believe this should be the IP of the machine on which jconsole or jvisualvm will be running, but this is not working for me.

I start the container like this:

docker run -d -v /Users/timbo/tomcat-jmx.sh:/usr/local/tomcat/bin/setenv.sh -p 8080:8080 -p 9999:9999 tomcat:8.0

so port 9999 is exposed. When I try to connect using jvisualvm connecting to localhost:9999 (which Docker for Mac will route to the container which is actually on 172.17.0.2) I get the error: Cannot connect to localhost:9999 using service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi

Any hints on what is wrong?

2 Answers
Related