Docker Container JVM Monitoring
Section titled “ 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
Section titled “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.
port 5002 (internal)"] end subgraph "Host Network" PORT["Host port 5002"] end GW["fa Spring Boot Gateway"] end subgraph "Agent Host" AGENT["fa JMX Monitoring Agent (IIS)"] end JVM -->|JMX| PORT GW -->|5002| PORT AGENT -->|8080| GW style JVM fill:#2678BD style PORT fill:#FFD525
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
Section titled “Configuring JMX Remote for Docker Containers”Step 1: Expose the JMX Port in Docker
Section titled “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.jarStep 2: Map the Port in Docker Run or Compose
Section titled “Step 2: Map the Port in Docker Run or Compose”Docker Run:
docker run -p 5002:5002 my-java-appDocker 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
Section titled “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
Section titled “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
Common Docker JMX Issues
Section titled “Common Docker JMX Issues”Spring Boot Gateway cannot connect to a containerized JVM
Section titled “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
Section titled “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
Section titled “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 Steps
Section titled “ Next Steps” Enable JMX Remote Monitoring
Costs and Licensing
Related Topics
Section titled “ Related Topics” Multi-JVM Monitoring
OS vs JVM Monitoring
JMX Troubleshooting Overview