adam bien's blog

How to establish JMX connection to JVM running in docker 📎

For remote monitoring of JVM processes (running in a docker container) you will have to activate remote JMX monitoring with the following JVM parameters:


        -Dcom.sun.management.jmxremote 
        -Dcom.sun.management.jmxremote.port=[RMI_PORT] 
        -Dcom.sun.management.jmxremote.rmi.port=[RMI_PORT]
        -Djava.rmi.server.hostname=[EXTERNAL_IP_OF_THE_CONTAINER]    

Both RMI_PORTs could have the same value (e.g. 9090). The EXTERNAL_IP_OF_THE_CONTAINER has to be the IP address with which the JVM process is accessible. Localhost or 127.0.0.1 won't work.

The following two parameters completely disable transport encryption and access control. They increase convenience and disable security at the same time:


        -Dcom.sun.management.jmxremote.ssl=false 
        -Dcom.sun.management.jmxremote.authenticate=false 

Given the RMI_PORT=9090, you can launch the process with docker run -p 8080:8080 -p 9090:9090 --name jmx airhacks/tomee-jmx and connect with jvisualvm, jconsole, jmc with EXTERNAL_IP_OF_THE_CONTAINER:9090.

Checkout out the instrumented TomEE dockerfile: tomee-jmx from docklands

See you at Java EE Microservices. and Tuning and troubleshooting Java EE 7 Microservices Is Munich's airport too far? Learn from home: javaeemicro.services.