{"id":644,"date":"2022-03-26T20:43:00","date_gmt":"2022-03-27T01:43:00","guid":{"rendered":"https:\/\/blog.felineflock.com\/?p=644"},"modified":"2024-01-03T20:59:45","modified_gmt":"2024-01-04T02:59:45","slug":"3-easy-steps-to-debug-docker-containers-in-vscode","status":"publish","type":"post","link":"https:\/\/blog.felineflock.com\/index.php\/2022\/03\/26\/3-easy-steps-to-debug-docker-containers-in-vscode\/","title":{"rendered":"3 Easy Steps to Debug Docker Containers in VSCode"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"541\" src=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-19-1024x541.png\" alt=\"\" class=\"wp-image-645\" srcset=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-19-1024x541.png 1024w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-19-300x158.png 300w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-19-768x406.png 768w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-19.png 1272w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p id=\"ember1468\">I haven&#8217;t seen yet a simple 3-step guide for when you have a Node app with multiple services so here it is.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember1469\">1 &#8211; Configure your package.json script to enable port watching on all services<\/h3>\n\n\n\n<p id=\"ember1470\">Add the inspect flag to your node call in the package.json script.<\/p>\n\n\n\n<p id=\"ember1471\">The &#8211;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.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"944\" height=\"302\" src=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-20.png\" alt=\"\" class=\"wp-image-646\" srcset=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-20.png 944w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-20-300x96.png 300w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-20-768x246.png 768w\" sizes=\"auto, (max-width: 944px) 100vw, 944px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember1473\">2 &#8211; Configure your Docker Compose YAML file to open ports<\/h3>\n\n\n\n<p id=\"ember1474\">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.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"614\" height=\"386\" src=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-21.png\" alt=\"\" class=\"wp-image-647\" srcset=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-21.png 614w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-21-300x189.png 300w\" sizes=\"auto, (max-width: 614px) 100vw, 614px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember1476\">3- Create the folder .vscode with a launch.json file containing the debugging configuration<\/h3>\n\n\n\n<p id=\"ember1477\">You can either create the file manually or <a href=\"https:\/\/code.visualstudio.com\/docs\/editor\/debugging#_launch-configurations\">follow these steps<\/a> 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, &#8230;).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"766\" height=\"550\" src=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-22.png\" alt=\"\" class=\"wp-image-648\" srcset=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-22.png 766w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-22-300x215.png 300w\" sizes=\"auto, (max-width: 766px) 100vw, 766px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember1479\">Launch Debug<\/h3>\n\n\n\n<p id=\"ember1480\">Once you&#8217;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.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"896\" height=\"674\" src=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-24.png\" alt=\"\" class=\"wp-image-650\" srcset=\"https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-24.png 896w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-24-300x226.png 300w, https:\/\/blog.felineflock.com\/wp-content\/uploads\/2024\/01\/image-24-768x578.png 768w\" sizes=\"auto, (max-width: 896px) 100vw, 896px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"ember1482\">Further reading:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/code.visualstudio.com\/docs\/nodejs\/nodejs-debugging\">https:\/\/code.visualstudio.com\/docs\/nodejs\/nodejs-debugging<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/code.visualstudio.com\/docs\/editor\/debugging\">https:\/\/code.visualstudio.com\/docs\/editor\/debugging<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I haven&#8217;t seen yet a simple 3-step guide for when you have a Node app with multiple services so here it is. 1 &#8211; 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 &#8211;inspect flag is what tells Node.js process [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-644","post","type-post","status-publish","format-standard","hentry","category-blog"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/644","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/comments?post=644"}],"version-history":[{"count":1,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/644\/revisions"}],"predecessor-version":[{"id":651,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/posts\/644\/revisions\/651"}],"wp:attachment":[{"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/media?parent=644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/categories?post=644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.felineflock.com\/index.php\/wp-json\/wp\/v2\/tags?post=644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}