Running jstack inside Docker container throws "Permission Denied"

1k views Asked by At

I am trying to get a thread dump of a Java service running inside Docker container. I got into the container terminal using the following command.

sudo docker exec -u 1000:0 -ti MyService /bin/bash

When I now run the following jstack command,

[ecs-user@myComputer /]$ jstack -l 436 > thread.dump

I get the following error.

bash: thread.dump: Permission denied

My docker container runAsUser is specified as ecs-user and that's the user the bash shell is running as. What permissions do I grant this user on which files to be able to do this thread dump? Or are there any other alternatives with jstack? Would appreciate any suggestions/advice. Thanks in advance.

1

There are 1 answers

1
apangin On

The issue has nothing to do with jstack. The error says, bash can't create thread.dump file in the root directory. This is quite expected, since / is typically writable only by root. Try creating the output file in a different directory.