docker容器内使用 gdb detach 到某进程中debug报错

在 docker 容器内使用 gdb 附加到正在运行的进程进行 debug :
gdb -p [pid]
但会输出附加失败的信息,如下:
Could not attach to process. If your uid matches the uid of the target process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.

解决方法

1、在容器外部( host 主机)上进行 detach
2、使用 CAP_SYS_PTRACE 功能(例如使用 --cap-add=SYS_PTRACE )启动容器。当然,如果无法重现同样问题的挂起,就不要使用这种方法。

你可能感兴趣的:(Bug,docker,容器,gdb,进程)