docker中调试失败
docker中gdb失败, ptrace:Operation not permitted
·
一、背景
在docker环境下使用gdb调试pg源码, gdb附加不上进程。
1.1 环境
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.6 LTS
Release: 18.04
Codename: bionic
$ docker --version
Docker version 20.10.7, build 20.10.7-0ubuntu5~18.04.3
二、处理过程
2.1 问题现象
postgres@2f9d6ce41c2b:/$ gdb --pid 5291
GNU gdb (Ubuntu 12.0.90-0ubuntu1) 12.0.90
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Attaching to process 5291
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.
(gdb)
2.2 尝试修改10-ptrace.conf文件
根据输出的信息,先尝试修10-ptrace.conf,将文件内容kernel.yama.ptrace_scope = 1 改为 0, 然而失败 😦
root@2f9d6ce41c2b:/# vi /etc/sysctl.d/10-ptrace.conf
root@2f9d6ce41c2b:/# sysctl -p /etc/sysctl.d/10-ptrace.conf
sysctl: setting key "kernel.yama.ptrace_scope", ignoring: Read-only file system
2.3 尝试直接修改ptrace_scope系统值
尝试直接修改值,仍然失败 😦
root@2f9d6ce41c2b:/# echo 0 > /proc/sys/kernel/yama/ptrace_scope
bash: /proc/sys/kernel/yama/ptrace_scope: Read-only file system
2.4 尝试加privileged选项
网上说在进入doker时,添加 --privileged 选项就可以了, 依然失败 😦
$ sudo docker exec --privileged -it build-pg /bin/bash
2.5 柳暗花明又一村
柳暗花明又一村,查看宿主机的对应的值,发现是1
root@trevor:~# cat /proc/sys/kernel/yama/ptrace_scope
1
修改值后,重新进入docker就正常了, 哇 😃
root@trevor:~# echo 0 > /proc/sys/kernel/yama/ptrace_scope
$ sudo docker exec -it build-pg /bin/bash
root@2f9d6ce41c2b:/# cat /proc/sys/kernel/yama/ptrace_scope
0
root@2f9d6ce41c2b:/#
更多推荐
已为社区贡献1条内容
所有评论(0)