How to use ipdb with docker-compose

How to use ipdb with docker-compose

June 22, 2020

Sometimes there may be in issue you need to debug which only occurs within a Docker container. Usually that involves using pdb or ipdb to set a breakpoint.

However, by default "ipdb.set_trace()" or "breakpoint()" won’t work. Here’s how to get it working.

1. Enable interactive mode by adding "stdin_open" and "tty" the following to your docker-compose.yml. For example:

version: "3"
services:
  app_tests:
    build: .
    stdin_open: true
    tty: true
    command: ./run_my_tests.sh

Now when you run your tests (docker-compose run app_tests) the terminal will stop at your break point.

2. Attach your local to the container.

In another terminal window run "docker attach <container_id>" which will bring up the ipdb interactive session in your terminal.

Latest Articles

New Job Board Exclusively for Outside IR35 Contracts Launches
How to validate Django ImageField dimensions
How to use ipdb debugger with docker-compose