-
Notifications
You must be signed in to change notification settings - Fork 179
Debugging inside of a docker container
Rich Chiodo edited this page Aug 7, 2025
·
4 revisions
Docker containers may not have the default setup required for debugging (especially attaching). If you're having trouble attaching, try following the steps below:
Your Dockerfile should include lines like so:
RUN apt-get update && \
apt-get install -y gdb && \
apt-get clean
GDB (for attach) needs to be able to ptrace another process. It's how the attach works. There's two ways you can enable this.
You can let the container have sudo over the environment it's running in (not recommended unless you're sure the container is safe)
Then you set this in your devcontainer.json
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt=seccomp=unconfined",
"--privileged"
],
"postCreateCommand": "echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope",
That will let GDB ptrace another process.
Before starting docker, run this in your host environment:
echo "kernel.yama.ptrace_scope = 0" | sudo tee /etc/sysctl.d/10-ptrace.conf
sudo sysctl --system
That will enable ptrace in all instances that start from that environment.
For more information see the man pages on ptrace: