On host machine, when dumping the heap of a Java process in container, I got an error:
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
acbf49802353 while:1.0 "/root/boot" 4 days ago Up 4 days trusting_fermi
# ps aux | grep java
root 134937 0.2 1.2 42757600 1662936 ? Sl Aug27 14:22 java -jar /root/while.jar
# jmap -heap 134937
Attaching to process ID 134937, please wait...
sun.jvm.hotspot.debugger.NoSuchSymbolException: Could not find symbol "gHotSpotVMTypes" in any of the known library names (libjvm.so, libjvm_g.so, gamma_g)
at sun.jvm.hotspot.HotSpotTypeDataBase.lookupInProcess(HotSpotTypeDataBase.java:585)
at sun.jvm.hotspot.HotSpotTypeDataBase.readVMTypes(HotSpotTypeDataBase.java:150)
at sun.jvm.hotspot.HotSpotTypeDataBase.<init>(HotSpotTypeDataBase.java:85)
at sun.jvm.hotspot.bugspot.BugSpotAgent.setupVM(BugSpotAgent.java:569)
at sun.jvm.hotspot.bugspot.BugSpotAgent.go(BugSpotAgent.java:493)
at sun.jvm.hotspot.bugspot.BugSpotAgent.attach(BugSpotAgent.java:331)
at sun.jvm.hotspot.tools.Tool.start(Tool.java:163)
at sun.jvm.hotspot.tools.HeapSummary.main(HeapSummary.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.tools.jmap.JMap.runTool(JMap.java:197)
at sun.tools.jmap.JMap.main(JMap.java:128)
Debugger attached successfully.
sun.jvm.hotspot.tools.HeapSummary requires a java VM process/core!
If attach into the container:
# docker attach trusting_fermi
bash-4.3# ps
PID USER TIME COMMAND
1 root 0:00 /bin/sh -c /root/boot
5 root 0:00 {busybox} ash /root/boot
6 root 0:00 java -jar while.jar
7 root 0:00 /bin/bash
27 root 0:00 ps
bash-4.3# jmap -heap 6
Attaching to process ID 6, please wait...
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process
How can I dump the heap of a Java process running in a container?