Docker-compose and pdb Docker-compose and pdb python python

Docker-compose and pdb


Use the following steps to attach pdb on any python script.

Step 1. Add the following in your yml file

stdin_open: truetty: true

This will enable interactive mode and will attach stdin. This is equivalent for -it mode.

Step 2.

docker attach <generated_containerid>

You'll now get the pdb shell


Try running your web container with the --service-ports option: docker-compose run --service-ports web


Till my experience, docker-compose up command does not provide an interactive shell, but it starts the printing STDOUT to default read-only shell.

Or if you have specified and mapped logs directory, docker-compose up command will print nothing on the attached shell but it sends output to your mapped logs. So you have to attach the container separately once it is running.

when you do docker-compose up, make it in detached mode via -d and connect to the container via

docker exec -it your_container_name bash