-
Notifications
You must be signed in to change notification settings - Fork 171
Debugging inside of a docker container
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.
You set this in your devcontainer.json
That will let GDB ptrace another process.
This allows the container to modify its host, not recommended unless you trust the container. This is way more permissive than just ptrace support
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: