Docker Container JVM Monitoring
This troubleshooting guide explains container monitoring for a container JVM so you can configure JMX remote access, container port mapping, and Docker network connectivity for the Nodinite JMX Monitoring Agent.
How JMX Monitoring Works with Docker
When a JVM runs inside a Docker container, the JMX port is bound inside the container and must be exposed to the host network using Docker port mapping. The Spring Boot Gateway then connects through the Docker network to the host IP on the mapped port.
Diagram: JMX monitoring for a JVM in a Docker container, where the JMX port is mapped from the container to the host network for Spring Boot Gateway access.
Configuring JMX Remote for Docker Containers
Step 1: Expose the JMX Port in Docker
Add JMX remote flags to the JVM startup command and expose the port in the Docker configuration:
java \
-Dcom.sun.management.jmxremote=true \
-Dcom.sun.management.jmxremote.port=5002 \
-Dcom.sun.management.jmxremote.rmi.port=5002 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Djava.rmi.server.hostname=<DOCKER_HOST_IP> \
-jar myapp.jar
Important
The
-Djava.rmi.server.hostnameparameter must be set to the Docker host IP address, notlocalhostor the container IP. This is the IP that the Spring Boot Gateway uses to connect back to the JVM. Without this setting, JMX connections from outside the container will fail.
Step 2: Map the Port in Docker Run or Compose
Docker Run:
docker run -p 5002:5002 my-java-app
Docker Compose:
services:
boomi-atom:
image: boomi/atom:latest
ports:
- "5002:5002"
environment:
- JAVA_OPTS=-Dcom.sun.management.jmxremote.port=5002 ...
Step 3: Configure in Nodinite JMX Agent
In the JMX Monitoring Agent Configuration:
- Address - The Docker host IP address, not the container IP
- Port - The mapped host port, 5002 in the example above
- Heap monitoring - Enable Heap Size thresholds for the target container JVM
- CPU monitoring - Enable CPU thresholds for the target container JVM
Kubernetes Considerations
For JVMs running in Kubernetes pods, JMX monitoring requires either:
- Exposing the JMX port via a Kubernetes
NodePortorLoadBalancerservice - Running the Spring Boot Gateway as a sidecar container in the same pod
Note
In Kubernetes environments, pod IP addresses change on pod restarts. Use a Kubernetes Service with a stable DNS name or static NodePort to provide a consistent JMX endpoint for the Nodinite monitoring agent.
Common Docker JMX Issues
Spring Boot Gateway cannot connect to a containerized JVM
Cause: The -Djava.rmi.server.hostname value is not set or is set to localhost or the container IP.
Resolution: Set -Djava.rmi.server.hostname=<DOCKER_HOST_IP> where <DOCKER_HOST_IP> is the IP address reachable by the Spring Boot Gateway.
JMX connects successfully but heap metrics show zero
Cause: The JVM inside the container reports zero heap if the container has memory limits but the JVM is not configured to respect them.
Resolution: Add -XX:+UseContainerSupport in JDK 8u191+ and JDK 10+ to enable JVM container awareness. This allows the JVM to detect Docker memory limits and set heap accordingly.
JMX expose settings are correct but metrics still fail
Cause: The published port is not reachable from the Docker host or another Docker network segment.
Resolution: Verify the container port mapping, host firewall rules, and Docker network routing between the Spring Boot Gateway and the target container.
Next Step
Enable JMX Remote Monitoring
Costs and Licensing
Related Topics
Multi-JVM Monitoring
OS vs JVM Monitoring
JMX Troubleshooting Overview