gdb does not hit any breakpoints when I run it from inside Docker container gdb does not hit any breakpoints when I run it from inside Docker container docker docker

gdb does not hit any breakpoints when I run it from inside Docker container


update 2020.01.04: Use the answer given by Kevin W Matthews --- it's better because it grants the necessary individual capabilities without elevating the entire container.


tldr; use

docker run --privileged

Longer: I was having some problems with gdb in docker---it was attempting (and failing) to disable address space layout randomization---but only on docker-machine, not on my native linux host.

When gdb failed to disable ASLR, all of my breakpoints would be ignored. Using the --privileged flag fixed my issue. Your mileage may vary.


Rather than elevating the entire container, I was able to use the option

--security-opt seccomp=unconfined

to fix address space randomization problems.

Some also recommend enabling the ptrace capability with

--cap-add=SYS_PTRACE

but this didn't seem to have any effect for me.

Here are the same settings for Docker compose:

security_opt:  - seccomp:unconfinedcap_add:  - SYS_PTRACE

Details are taken from this Stack Overflow post.


thanks the answer from @rubicks.

and if you can't use --privileged option(e.g. you are using a container from cloud), you can print stacktrace from your program:

How to automatically generate a stacktrace when my gcc C++ program crashes