Search code examples
dockerjvmdocker-swarm

How to dump jvm memery in docker swarm mode?


My springcloud applications are running in docker swarm mode, and recently I found that the memory usage is not in the normal level. I want to use some tools like jmap or something else to dump the heap so that I can change the params of jvm and solve the problem.

I have tried to use some tools like arthas ,but it failed because of the pid 1 problem. We can not attach to a process which id is 1-5.

How can I know the heap usage ( eden、survivor etc) ?


Solution

  • The easiest way I think is to get into container's shell and install necessary tools right there. Use this on a node with the application container to start interactive session:

    docker exec -u root -it <container_name> sh
    

    Stop the container after you finished to recreate it and thus clean up.

    If at some point you need to extract a file from container (e.g. dump) use docker cp from another console on the node:

    docker cp <container_name>:<path_in_container> <local_path>