»
Introduction
The tutorials I’ve found [1] [2] are modifying the Dockerfile and create their own image, but this is not necessary, you can just pass the required environment variables to docker run
.
»
Java
1
| docker run -e JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.rmi.port=9090 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=localhost" -p 9090:9090/tcp -d some-java-image
|
»
Tomcat
Basically, it’s the same as for all other Java applications, but for Tomcat, you should use CATALINA_OPTS
instead of JAVA_OPTS
, which would still work (but a good argument against).
1
| docker run -e CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.rmi.port=9090 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=9090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=localhost" -p 8080:8080/tcp -p 9090:9090/tcp -d tomcat
|
»
VisualVM
In the docker container, JMX is exposed to port 9090. To profile with VisualVM right click on Local -> Add JMX Connection -> Connection: localhost:9090