How can I gdb attach to a process running in a docker container? How can I gdb attach to a process running in a docker container? docker docker

How can I gdb attach to a process running in a docker container?


You can attach to the process with gdb instance running in your container by attaching to the running container via lxc-attach.

Note: gdb has to be already installed in that container or you have to install it.

# find your container IDsudo docker ps# list of your containers - container ID is 1234567890# find your full container IDsudo docker ps --no-trunc -q| grep <short ID>sudo lxc-attach -n <container long ID>root@1234567890:/## optionally, you can install gdb now if it is not installed# yum install gdbroot@1234567890:/# gdb...(gdb) attach 1

UPDATE 2017-04:

There is an easier workflow using docker exec now available (thanks to @42n4).

# find your container IDsudo docker ps# list of your containers - container ID is 1234567890docker exec -i -t 1234567890 /bin/bashroot@1234567890:/## optionally, you can install gdb now if it is not installed# yum install gdbroot@1234567890:/# gdb...(gdb) attach 1