gdb in docker container returns "ptrace: Operation not permitted."
I discovered the answer - the container needs to be started with strace capabilities
Adding this to my docker-compose.yml file allows GDB to work
cap_add:
- SYS_PTRACE
Or it can also be passed on the docker command line with --cap-add=SYS_PTRACE
Related videos on Youtube
![Adrian Cornish](https://i.stack.imgur.com/rJPoP.jpg?s=256&g=1)
Adrian Cornish
Current specialty is real time financial market data with sub microsecond latency Protocols: UDP, TCP, UDP Mutlicast, FIX, FIX/FAST Specialist in: US Treasury/Fixed Income related trading systems include: ICAP, BrokerTec, ESpeed, Govex, ELX, Cantor, BGC. Languages: C++ (25 years), STL (20 years), SQL (17 years), C (18 years), PHP (18 years) Databases: MySql (18 years), C-ISAM (3 years), D-ISAM (1 year) Web Related: HTML (18 years), Apache (18 years) OS: Unix’s (13 Years), VMS (11 years), Window/Dos (25 years), Linux (20 years) Been programing with real computers since I was 16 - been paid for it since I was 18 Worked on VAX, RS600, Intel, Sparx, Ultrix and all sorts of in between
Updated on July 09, 2022Comments
-
Adrian Cornish almost 2 years
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 reportsReading 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
Host OS is Fedora 25 with docker from their repos and container is a official centos6.8
-
odk over 7 yearsNothing in host dmesg output? It might be blocked by SELinux, check here: fedoraproject.org/wiki/Features/SELinuxDenyPtrace
-
user2915097 over 7 yearslooks like github.com/docker/docker/issues/21051
-
-
beerbajay over 5 yearsThis is also relevant when trying to take a heap dump for a java program with jmap or jvisualvm and getting
sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 1: Operation not permitted
as an error