Docker Community Forums

Share and learn in the Docker community.

Debugging `dockerd` with `dlv`


I am trying to understand something inside dockerd using dlv debugger. Unfortunately, every time I am trying to do that I am facing errors. I can’t do dlv exec nor dlv attach.

The following diff shows some changes I applied to make sure that some go optimizations are avoided and debugging is possible:

diff --git i/hack/make/.binary w/hack/make/.binary
index d56e3f3..e6835fa 100644
--- i/hack/make/.binary
+++ w/hack/make/.binary
@@ -84,6 +84,7 @@ hash_files() {
        go build \
                -o "$DEST/$BINARY_FULLNAME" \
                "${BUILDFLAGS[@]}" \
+               -gcflags="all=-N -l" \
                -ldflags "

I also modified to make sure I don’t use plain exec but dlv exec dockerd -- $@. Unfortunately every time I get the following error:

Could not create config directory: mkdir /root/.config: permission denied.could not launch process: could not get .debug_frame section: could not find .debug_frame section

Does anyone have an idea what could be causing it?


OS: Fedora 31

go version

go version go1.13.10 linux/amd64
dlv version

Delve Debugger
Version: 1.4.0
Build: $Id: 67422e6f7148fa1efa0eac1423ab5594b223d93b $
docker version

Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b7f0
 Built:             Wed Mar 11 01:27:05 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Found it… It was the presence of -w in the LDFLAGS.

Step 1 make app

func main() {
v := “test”
fmt.Println(“Hello World!”)
Step 2 create vscode debug config (PS: some string magic would be nice so you don’t have to hardcode your remotePath ${remove /Users/gert from filedir path magic})

“version”: “0.2.0”,
“configurations”: [
“name”: “docker”,
“type”: “go”,
“request”: “launch”,
“mode”: “remote”,
“backend”: “native”,
“remotePath”: “/go/src/myapp”,
“port”: 2345,
“host”: “”,
“program”: “${fileDirname}”,
“env”: {},
“args”: ,
“showLog”: true
Step 3 create docker container and start it up in bash

docker run -it --rm
-v /Users/gert/go:/go
-w /go/src/myapp
-p 2345:2345
–security-opt apparmor=unconfined
–cap-add SYS_PTRACE
myappcontainer bash
Step 4 in your container launch headless dlv

dlv debug --headless --listen=:2345 --log
Step 5 breakpoints work until you try to step into everything that is inside GOROOT


Step 6 and last but not least, the restart button is not working


DEBU[0051] continuing layer=debugger
DEBU[0069] stepping layer=debugger
DEBU[0341] halting layer=debugger
[1]+ Stopped
Should not halt just restart the headless server probably related to

I think you misunderstood… I wanted to debug the dockerd itself. Not an app inside a Docker container.