Using ipdb with Docker Compose for interactive debugging
May 30, 2015 Comments
Back in the early days of Docker Compose, when it was still called Fig, you couldn't use ipdb with it to do interactive debugging because the container's service ports weren't exposed when using the run command. This has been fixed by including a ---service-ports option to the docker-compose run command.
Below is a sample usage for one of my Django projects, EZ Price Alerts.
In my detail view, I added import ipdb; ipdb.set_trace() to break into the debugger.
... class ProductDetailView(DetailView): model = Product slug_field = 'asin' slug_url_kwarg = 'asin' def get_context_data(self, **kwargs): import ipdb; ipdb.set_trace() context = super(ProductDetailView, self).get_context_data() context['price_type_choices'] = PriceType.CHOICES ...
I then started the Django container/service with docker-compose run, making sure that I included the --service-ports option.
docker-compose run --service-ports django
Now when I visit the page that loads that detail view, I'll get a TTY to do my debugging.
Django version 1.7.8, using settings 'ezpricealerts.settings.local' Development server is running at http://0.0.0.0:80/ Using the Werkzeug debugger (http://werkzeug.pocoo.org/) Quit the server with CONTROL-C. > /ez-price-alerts/ezpricealerts/apps/products/views.py(20)get_context_data() 19 ---> 20 context = super(ProductDetailView, self).get_context_data() 21 context['price_type_choices'] = PriceType.CHOICES ipdb> self.object.title u'ASUS Zenbook UX305FA-ASM1 13.3-Inch Ultra-Slim Aluminum Laptop, 8 GB RAM and 256 GB SSD' ipdb>
That's it :).