paint-brush
Debugging: Using PDB in Dockerized Environmentby@melvinkcx2
9,771 reads
9,771 reads

Debugging: Using PDB in Dockerized Environment

by Melvin Koh
Melvin Koh HackerNoon profile picture

Melvin Koh

@melvinkcx2

Software Engineer | Maintainer of fastapi-events

January 13th, 2020
Read on Terminal Reader
Read this story in a terminal
Print this story
Read this story w/o Javascript
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Docker and Docker Compose are the most used tools under the DevOps category, according to The State of Developer Ecosystem 2019 survey by JetBrains. 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 problem. For the sake of simplicity, I'll be using a toy app I created throughout this tutorial.
featured image - Debugging: Using PDB in Dockerized Environment
1x
Read by Dr. One voice-avatar

Listen to this story

Melvin Koh HackerNoon profile picture
Melvin Koh

Melvin Koh

@melvinkcx2

Software Engineer | Maintainer of fastapi-events

About @melvinkcx2
LEARN MORE ABOUT @MELVINKCX2'S
EXPERTISE AND PLACE ON THE INTERNET.

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

bdb.BdbQuit
error:

image

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

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

version: '3'

services:
  web:
    build: .
    volumes:
      - .:/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>
image

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

image


L O A D I N G
. . . comments & more!

About Author

Melvin Koh HackerNoon profile picture
Melvin Koh@melvinkcx2
Software Engineer | Maintainer of fastapi-events

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Hashnode
Learnrepo
Hashnode
X REMOVE AD