Colin Miller
May 2 · 2 min read

I’ve recently migrated my web application to run inside docker containers and use docker-compose to spin up all the required dependencies in their own containers (Postgres and Redis, in my case). This application uses Python’s Flask framework and I use pdb to debug issues.

While researching solutions, I first ran into this article by Vladyslav Krylasov that suggested adding some configuration to my docker-compose.yaml and using a module called remote-pdb with a telnet client. This worked, but it was a little more cumbersome than I wanted.

My solution was to use docker attach. First, I still needed to edit my docker-compose.yaml file to add the stdin_open and tty attributes to my application container:

stdin_open: true
tty: true

Next, I needed to change the way I started my service. I edited my docker-compose up line to run in the background with docker-compose up -d and then ran docker attach application to show all the container’s output in my console window. Now I get the app’s output (and it looks identical to how it did when I was running the Flask server locally) and can interact with it in pdb.

To test, I added a debugging line to a route:

@bp.route('/', methods=['GET'])
def index():
import pdb; pdb.set_trace()
return render_template(‘site/index.html’)

Then I pointed my browser to it and checked my console…

-> return render_template(‘site/index.html’)


Colin Miller

Written by

I’m a software engineer that specializes in front-end web development. Learn more at

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade