在docker里面用strace -p pid 查看进程当前调用栈报错
$ strace -p 7
ptrace(PTRACE_ATTACH, ...): Operation not permitted //报错信息
解决办法
I would like to add that I needed --security-opt apparmor=unconfined along with the options that @wisbucky mentioned. This was on Ubuntu 18.04 (both Docker client and host). Therefore, the full invocation for enabling gdb debugging within a container is:
docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --security-opt apparmor=unconfined
摘自 How to solve “ptrace operation not permitted” when trying to attach GDB to a process?
docker 官方解析
The solution for enabling of ptrace and PTRACE_ATTACH in Docker Containers