How to debug Flask (running in docker-compose) in VS Code
TLDR: Install debugpy and run the debugpy in your package.json. Then launch “Python: Remote Attach” in VS Code. I assume you are here because you cloned a Flask python application and you want to debug it in Visual Studio Code. You tried fooling around in launch.json with the “Python: Flask” app. Perhaps with the Docker: add Dockerfiles to workspace... command. Who knows what you tried, the VS Code docs can be confusing. The point is, it didn’t work and now you are here. I’ll spare you the words, here’s the code. Prerequisites You have a Flask application opened in VS Code (and you want to debug it). Your Flask app is similar to the Cookiecutter Flask application (See https://github.com/jamescurtin/demo-cookiecutter-flask), which uses node. This means there’s a package.json that contains commands like start to run the app (webpack + flask). You have a Dockerfile that creates an environment to run the Flask app in. You have docker-compose.yml to build & run the Dockerfile. There’s a app.py that starts your Flask app. Step 1: Install debugpy in Dockerfile We’ll want to use debugpy. It’s a nifty debugger for Python that can debug a file/module (among other) and wait until a Listener (VS Code) has attached itself to the debug proces. ...