DEV Community

Cover image for Dockerize a Flask app and debug with VSCode

Dockerize a Flask app and debug with VSCode

Thiago Pacheco on March 02, 2021

Introduction If you had tried setting up the VSCode debugger with docker before, you might have seen that it can be a bit more complicat...
Collapse
 
icecoffee profile image
Atulit Anand • Edited

Why do we use this when we have virtual environment for python apps? I mean after all both are just techniques to isolate the app so it can run independently.
Any how cheers mate for the job well done.

Collapse
 
pacheco profile image
Thiago Pacheco

Yes, they both isolate the code but they have different purposes.
The virtual env takes care of the python dependencies only, but the docker container will take care of creating the entire environment (but using your current system resources), similar to creating a virtual machine in your computer and installing all the necessary dependencies like a specific Python version for example.
This is especially good because it removes that issue of incompatible software versions between coworkers' computers and the prod, staging and dev environments.
Basically, you have a production-ready setup.
Linode has a great article about why and when to use docker, maybe this could be a good help to you:
linode.com/docs/guides/when-and-wh...

Collapse
 
icecoffee profile image
Atulit Anand

Ty you're great

Collapse
 
bizzguy profile image
James Harmon • Edited

Once I started using Docker, VS Code no longer recognized new packages entered in requirements.txt. The app itself worked fine, but VS code showed error messages. Is there any way to get VS code to recognize newly added packages?

Collapse
 
diogosimao profile image
Diogo Simão

"-m", "app", "--wait-for-client", "--multiprocess",

is it really necessary? it was crashing the execution today.

Collapse
 
diogosimao profile image
Diogo Simão

great tutorial

Collapse
 
pacheco profile image
Thiago Pacheco

Hey Diogo!
No, this is not required, It just makes the execution of the app await for the debugger connection.

Collapse
 
aymhenry profile image
Ayman Henry

Kindly fix this

for windows
.\venv\Scripts\activate

you wrote.
./venv/Scripts/activate

Collapse
 
atkumar profile image
Ashutosh Kumar

This just saved my life from putting logs at random places to debug flask running in Docker.