Reputation: 2684
I have a Spring Boot application running in a container on a remote machine, which JVM parameters I have to use to connect to it through Java Mission Control or JVisual VM (via JMX)?
Upvotes: 2
Views: 5355
Reputation: 370
Via Docker Compose you can use the environment JAVA_OPTS
. It is not safe to expose JMX port outside of cluster.
...
logging-filter:
image: docker.io/amusarra/eventbus-logging-filter-jaxrs:latest
container_name: logging-filter
networks:
- logging_filter_network
environment:
- JAVA_OPTS=-Dcom.sun.management.jmxremote.port=9091
-Dcom.sun.management.jmxremote.rmi.port=9091 -Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=127.0.0.1
...
On this repository, there is a complete configuration example for JMX.
On the topic of Java Flight Recorder, Red Hat sponsors the Cryostat project, which is an open source alternative to Mission Control, allowing Java Flight Recorder to be used in containerized environments. I invite you to read the article Monitoring Quarkus JVM Mode With Cryostat for further details.
This article shows how to use Java JMX in container environments, specifically on Red Hat OpenShift.
Upvotes: 0
Reputation: 2684
Start the container with the following JAVA_OPTIONS:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.rmi.port=7012
-Dcom.sun.management.jmxremote.port=7012
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=<public_ip>
Also, make sure you expose the same port you are listening inside the container (e.g. docker run container -p 7012:7012 ...)
Upvotes: 9