Before you go, check out these stories!

Hackernoon logoDebugging: Using PDB in Dockerized Environment by@melvinkcx2

Debugging: Using PDB in Dockerized Environment

Author profile picture

@melvinkcx2Melvin Koh

Software Engineer. Pythonista, JavaScripter. Find me on Twitter @melvinkcx2 ๐Ÿ˜

Docker, along with Docker Compose are the most used tools under the DevOps category, according to The State of Developer Ecosystem 2019 survey by JetBrains. Chances are if you're using Docker/Docker Compose for deployment, you'll most likely be using them for local development as well. If you only use Docker for deployment but a virtual environment for local development, you may want to look into using Docker for development to reduce the parity between dev/prod environments, as suggested in the Twelve-Factor Methodology.

In this article, you'll be learning how to use PDB (Python DeBugger) in a Dockerized Python environment. If you are reading this, I believe you already have your Docker set up and are perhaps trying to solve the


For the sake of simplicity, I'll be using a toy app I created throughout this tutorial. You can find it here.

In order to use

, you need to run your containers in interactive mode. To do so, ensure your Docker container accepts
and runs in
mode by adding these two lines in your Docker service in your
(or your docker-compose configuration)

version: '3'

    build: .
      - .:/app
    stdin_open: true   # Add this line into your service
    tty: true   # Add this line into your service

After those lines are added, start your Docker container as usual. In my case, I run:

docker-compose up -d

Once your Docker container is running, attach your terminal standard streams to your running container:

docker attach <your_container_id>

Here you go! Now, you are in your PDB session.

Author profile picture

@melvinkcx2Melvin Koh

Read my stories

Software Engineer. Pythonista, JavaScripter. Find me on Twitter @melvinkcx2 ๐Ÿ˜


Join Hacker Noon

Create your free account to unlock your custom reading experience.