DEV Community

Lucas Schiavini
Lucas Schiavini

Posted on • Originally published at lucas-schiavini.com on

Debugging NodeJS within a Docker Container on VSCode


Image Source

So hello, it’s been a while, and I haven’t being keeping up with my daily dispatches, or maybe my days are longer than yours. Relativity man, who knows?

So I was playing around with a Node.js project hosting it using Docker alongside a Postgres database.

And I was all happy and dandy until I wanted to debug an error on VSCode.

And I couldn’t.

So I went far and wide, talked with many friends (I wish), and came across this cool article Debugging uncompiled Typescript code running on a Docker container | by Mitsuhide Ohi | Medium.

This article pointed me towards the right direction, but I had to add a few things.

1 — First of all, I didn’t need to add a debug script to my package.json. I merely replaced my --inspect flag with itself + server_address:port --inspect=0.0.0.0:9229.

2 - I did add the next line on my tsconfig.json.

"sourceMap": true
Enter fullscreen mode Exit fullscreen mode

3 — Here’s where things differ a lot from the article, my vscode launch.json configuration didn’t use the sourceMapPathOverrides (it did nothing for me).

Instead I replaced it with these two cool properties ( remoteRoot and localRoot):

4 — Now to the docker-compose.yml file, I added to my mainApp service the docker port for debugging

5 — After all that, I had to run docker-compose up -d --build --force-recreate since I changed the docker-compose.yml file.

And then BOOM! It worked.


😗 Enjoy my writing?

Forward to a friend and let them know where they can subscribe (hint: it’s here).

Anything else? Just say hello in the comments :).

Join an Exclusive Tech Friendly Community! Connect with like-minded people who are interested in tech, design, startups, and growing online — apply here.

Top comments (2)

Collapse
 
viaanamichale profile image
Vishangi M

Thank you so much for sharing such an informative blog with us. Also, I like your way of explanation this blog and looking for other blogs on similar topic.
Regards, Viaana.
Hire NodeJS Developer from CMARIX TechnoLabs Pvt. ltd.

Collapse
 
lschiavini profile image
Lucas Schiavini

Just you wait when I drop the Hosting a Ghost Blog using Docker on a Free Cloud Infrastructure