DEV Community

sidpalas
sidpalas

Posted on

How to Debug Docker Containers (Python + VSCode)

When containers are working they are amazing and make running your code across different environments seamless...

However, when something goes wrong, the additional layers of abstraction can make debugging them difficult.

Here are three techniques you can use to debug them:

1) Override the entrypoint at runtime and exec into the container
2) Copy files into or out of the container for inspection/comparison
3) Run a remote debugger inside the container and attach to it over the network

I created a video walking through how to use these three techniques:

Leave your own tips in the comments!

Top comments (3)

Collapse
 
yeorj profile image
George Alfaro • Edited

You're correct. I believe he uses venv for non-containerized development to keep his python packages tidy; it's good practice. Sometimes you want to hack around straight on your machine and not run a container since it can be a lot simpler to test a new feature or debug without dealing with containers.

Collapse
 
sidpalas profile image
sidpalas

Exactly! In the video, I am comparing how the test cases behave differently inside vs outside the container. The virtual environment is to handle the packages running directly on my host system.

Thread Thread
 
mono-ne profile image
Rodolfo González Romero

Pyenv is also a good alternative locally, it allows you to work with multiple python versions