Mount a Debugger
How to debug a Minimus container by mounting debug tools
Most production Minimus container images do not include a shell. While we recommend use of the dev
tagged Minimus images for troubleshooting whenever possible, sometimes it may be necessary to mount a debugger on a production container.
Prepare the debugger container
We can use the Minimus BusyBox image as our debugger container. We will first create the container (without running it), extract its filesystem, and place it in a local directory.
docker export
saves the root filesystem of the container to a tar archive|
(the pipe) passes the output directly into the next command to avoid creating an intermediate tar filetar -xC debugger
extracts the archive files and saves them to the local directory
Start the target container and mount the debugger image
Start the debugging session
Exec into the target container to start a debug session. This is possible because the debugger container and target container (my-image
) share namespaces and cgroups.
Update the system's executable search path
Now that we’ve mounted the BusyBox toolkit, we need to add the directory /.debugger/bin
to the current shell’s path environment variable to make the tools executable from anywhere. This works because the BusyBox toolkit in the mounted volume is statically linked.
You can either prepend or append the debug tools. In the case of a name collision:
- If the debugger was appended, the binaries from the target container will take precedence.
- If the debugger was prepended, the binaries from the debugger container will take precedence.
Note that this change only affects the current shell session.
Ready to debug!
That’s it. You are now ready to use the BusyBox toolkit as if it were natively part of the target container.
For example, you can explore the filesystem of the target container and list the running processes and network interfaces:
The output should show you the information for your target Minimus container as if you were running the command directly inside it.
This article was inspired by Ivan Velichko’s blog.