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

I have a lengthy process in a docker container that I would like to connect gdb to see which threads are running and get the stack. I can connect to the process from the host, but I cannot allow any characters, because the executable file is located elsewhere in the file system (it is installed at the docking station level), and the general system libraries are all stuck in the docker file system image somewhere in / var / lib / docker.

I can generate the main file and use gdb to look at it, indicating the host path to the executable, but since the system libraries are in the wrong places and loaded in the wrong locations in the corefile, I do not get any information from this.

Do I have any options that I forgot?

+6
source share
1 answer

You can connect to a process with a gdb instance running in your container by connecting to a running container via lxc-attach .

Note. gdb should already be installed in this container or you need to install it.

 # find your container ID sudo docker ps # list of your containers - container ID is 1234567890 # find your full container ID sudo 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 gdb root@1234567890 :/# gdb ... (gdb) attach 1 

UPDATE 2017-04:

There is a simpler workflow using the now available docker exec (thanks @ 42n4).

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

All Articles