How to dump heap from a Java program running in container

There’s no difference between using “docker attach” and “docker exec -it”. They both can get into the container by /bin/bash. The error remains the same:

# /opt/jdk1.7.0_80/bin/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

I am wondering if it is because Java debug tool jmap cannot find the process information of Java program running in container. But how to make it work?

Help!