Follow the below steps to take the thread and Heap dumps from a docker container
1. Run the below command to bash into the container. Please change the CONTAINER_NAME appropriately
docker exec -it CONTAINER_NAME bash
2. Then type jps to find the all the Java application details and extract the PID for your application
jps
3. Then run the below command to get the thread dump. Please change the PID(Process id) appropriately.
jstack PID > threadDump.tdump
4. Then run the below command to get the Heapdump. Please change the PID appropriately
jmap -dump:live,format=b,file=heapDump.hprof PID
5. Then exit from the docker container and download the threadDump.tdump and heapDump.hprof from the docker container by running the below command. Please change the CONTAINER_NAME appropriately
sudo docker cp CONTAINER_NAME:threadDump.tdump . sudo docker cp CONTAINER_NAME:heapDump.hprof .
Works great. Thanks. Made a dev happy today . Devops by Google. happy friday.
Works like a charm!!
Works great, I just didn’t know how to find the PID as `ps` was showing nothing. Using `ps aux` helped.