I\'m trying to attach a program with gdb but it returns:
Attaching to process 29139
Could not attach to process. If your uid matches the ui
I would like to add that I needed --security-opt apparmor=unconfined
along with the options that @wisbucky mentioned. This was on Ubuntu 18.04 (both Docker client and host). Therefore, the full invocation for enabling gdb debugging within a container is:
docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --security-opt apparmor=unconfined