docker 容器中的 gdb 返回“ptrace:不允许操作".

人气:722 发布:2022-10-16 标签: centos c++ docker fedora gdb

问题描述

我在容器和主机上检查了 /proc/sys/kernel/yama/ptrace_scope - 两者都将值报告为零,但当附加到 pid 时,一个 gdb 报告

I've checked /proc/sys/kernel/yama/ptrace_scope in the container and on the host - both report the value as zero but when attached to pid one gdb reports

Reading symbols from /opt/my-web-proxy/bin/my-web-proxy...done.
Attaching to program: /opt/my-web-proxy/bin/my-web-proxy, process 1
ptrace: Operation not permitted.

我也尝试过使用特权标志附加到容器

I've also tried attached to the container with the privileged flag

docker exec --privileged -it mywebproxy_my-proxy_1 /bin/bash

主机操作系统是 Fedora 25,带有来自其 repos 的 docker,容器是官方的 centos6.8

Host OS is Fedora 25 with docker from their repos and container is a official centos6.8

推荐答案

我找到了答案——容器需要启动strace能力

I discovered the answer - the container needs to be started with strace capabilities

将它添加到我的 docker-compose.yml 文件允许 GDB 工作

Adding this to my docker-compose.yml file allows GDB to work

cap_add:
    - SYS_PTRACE

或者也可以在docker命令行中使用--cap-add=SYS_PTRACE

Or it can also be passed on the docker command line with --cap-add=SYS_PTRACE

737