3 steps to debug your Docker container in VSCode
I haven't seen yet a simple 3-step guide for when you have a Node app with multiple services so here it is.
1 - Configure your package.json script to enable port watching on all services
Add the inspect flag to your node call in the package.json script.
The --inspect flag is what tells Node.js process to listen for a debugging client. Nodemon makes the node app automatically restart when you change the source code but this will work with plain Node too.
2 - Configure your Docker Compose YAML file to open ports
Edit your docker-compose.yaml to add port 9229 under your app service configuration. If you have more than one service, use a different port for each: 9229, 9230, and so forth.
3- Create the folder .vscode with a launch.json file containing the debugging configuration
You can either create the file manually or follow these steps to create a launch.json file. If your app has more than one service, you will have to have one configuration for each service and the port has to match (9229, 9230, ...).
Launch Debug
Once you've started Docker and built the app, you can open a file on the debug tab, set breakpoints and click the green arrow to start debugging.