tdudgeon
tdudgeon

Reputation: 365

Connecting with JMX using Docker for Mac

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?

Upvotes: 3

Views: 1744

Answers (2)

tdudgeon
tdudgeon

Reputation: 365

OK, I think I managed to find it eventually. Setting the value of java.rmi.server.hostname to the hostname of the host (e.g. mymac.local, or whatever is returned by hostname) seem to get it working. All other settings were OK.

Upvotes: 2

Tarun Lalwani
Tarun Lalwani

Reputation: 146610

Docker for Mac works in a bit different way. The port you map actually gets mapped to the Linux VM it is running in the background. This VM usually has in IP 192.168.99.100. So you should try and connect to 192.168.99.100:9999

To verify what is the IP of your VM, open the Docker CLI terminal and execute below

echo $DOCKER_HOST
tcp://192.168.99.100:2376

Upvotes: 0

Related Questions