Docker image to allow for gdb debugging with Python extensions
1.8K
Debugging Python applications using gdb inside a virtualenv is a bit of a pain (especially on e.g. OS X), so I solved that using Docker.
This image allows you to debug Python applications using gdb's Python support. In order to use it, cd to your project directory, and start a container using the following command:
docker run -ti --privileged --cap-add=SYS_PTRACE \
--rm -v $PWD:/project \
objectified/python-debug
From there on, you can pip install your requirements (pip is available inside the container, you can do pip install -r requirements.txt) and start your application either through gdb or as a separate process to which you let gdb connect.
For example, do this inside the container you just started:
$ cd /project
$ pip install -r requirements.txt
$ python your-longrunning-app.py
Now get another shell on the container:
$ docker exec -ti <your container id> /bin/bash
Changedir to /project, find the pid of the Python process you started earlier, and connect to it using gdb:
$ cd /project
$ gdb python <your pid>
From then on, you can do things like list threads, py-list (to see the current stack position), py-locals (to see variables in the current scope) and so on.
More info here:
Content type
Image
Digest
sha256:519f24f1b…
Size
188.8 MB
Last updated
about 11 years ago
docker pull objectified/python-debug