Andy McKay

Jun 01, 2015

Docker in development (part 3)

Tips for developing with Docker.

Running pdb

This is a Python specific tip, but pdb is Python specific debugger. Using pdb is pretty useful for Python development, but this tip can apply to any processes that use a pseudo terminal to interact with the process.

If you use docker-compose, you can’t actually run your process and enter an interactive debugging session. There’s been some requests for that but there’s a simpler way. Since we are using a process manager, all you have to do is:

  • exec into the container, eg: docker exec -ti $(docker ps | grep [servicename] | awk '{print $1}') /bin/bash
  • stop the process using your process manager, eg: supervisorctl stop [servicename]
  • start the process from the shell, eg: python runserver

Then you’ll be able to re-trigger requests and get to your Python prompt. Bear in mind, you’ll have to ensure that any environment variables you set are set correctly. You’ll be able to use pdb as much as want. As soon as you stop and restart the container, it will revert back to it’s normal state again.

See also part 2.