To begin (check also this screencast to watch how the steps below play out in VS Code): However, with relatively minor changes, one can debug a dockerized Python app in a similar way.
VISUAL STUDIO CODE PYTHON DEBUGGING CODE
In what follows I tackle those questions for that code example and FastAPI specifically.
VISUAL STUDIO CODE PYTHON DEBUGGING HOW TO
How to add new features and improvements? How to come up with the changes needed to fix the bug? My “ship in the bottle” had a flaw that needed a fix.
Very soon somebody noticed that the code was affected by a bug that made it struggle when handling some input. I recently published on GitHub a simple example of dockerized API based on FastAPI and streamlit. VS Code is a popular code editor developed by Microsoft which enables development in containers via one of its extensions (note that some of the content here may become obsolete as new versions of the editor and extensions are released). In what follows, I’ll describe an example of development in containers using Visual Studio Code (VS Code). Through development in containers one can perform code changes from within a container and when done with modifications, voilà, the updated application is ready to be run and deployed! The coding equivalent of this idea is remote development in containers. Wouldn’t it be nice to… magically enter the bottle and carry out all the desired changes to the ship while inside the bottle? However, if the ship doesn’t fit (the code crashes) or needs upgrades (new functionality), one needs to take it out and then inside the bottle again (modify the code, build and rerun the container), and again, and again… Working locally on code which eventually will be running in a container can feel a bit like building and upgrading a model ship that needs to fit inside a bottle: one can build the ship (create the initial version of the code), put it in the bottle (build the container with the code) check if it fits inside nicely (run the code successfully in the container). For example, to see how newly applied code changes affect the behavior of the app one would need to rebuild and rerun the container, and this can be slow and inefficient. There’s a small catch though: it can be cumbersome to develop code of a containerized application, because outside the container there won’t be an environment able to run it. How do you fix a ship if it’s inside a bottle?
Debugging Python FastAPI apps in Docker containers with Visual Studio Code