The problem
I am able to set and reach a breakpoint if I compile and run from the host, but if I do it from within the docker container gdb does not
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
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:unconfined
cap_add:
- SYS_PTRACE
Details are taken from this Stack Overflow post.
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.