1"use strict";(self.webpackChunkpixelpoint_website=self.webpackChunkpixelpoint_website||[]).push([[4066],{6174:function(e,t,o){o.r(t),o.d(t,{Head:function(){return w},default:function(){return f}});var n=o(8453),s=o(6540),r=o(4754);const a={annotations:r.hk,Code:r.Cy},i={staticMediaQuery:"not screen, (max-width: 768px)",lineNumbers:void 0,showCopyButton:!0,themeName:"dark-plus"};function c(e){const t=Object.assign({p:"p",a:"a",h2:"h2",span:"span",ul:"ul",li:"li",code:"code"},(0,n.RP)(),e.components);return a||p("CH",!1),a.Code||p("CH.Code",!0),s.createElement(s.Fragment,null,s.createElement("style",{dangerouslySetInnerHTML:{__html:'[data-ch-theme="dark-plus"] { --ch-t-colorScheme: var(--ch-0);--ch-t-foreground: var(--shiki-token-embed);--ch-t-background: var(--shiki-background-editor);--ch-t-editor-background: var(--shiki-background-editor);--ch-t-editor-foreground: var(--shiki-token-embed);--ch-t-tab-activeBackground: var(--shiki-background-editor);--ch-t-tab-inactiveBackground: var(--shiki-background-editor);--ch-t-tab-border: var(--shiki-menu-background);--ch-t-tab-activeBorder: var(--shiki-background-editor);--ch-t-editorGroupHeader-tabsBackground: var(--shiki-background-header);--ch-t-input-foreground: var(--shiki-token-embed);--ch-t-sideBar-foreground: var(--shiki-token-embed); }'}}),"\n",s.createElement(t.p,null,"More and more teams are moving their development environments to Docker containers. It brings a lot of advantages, such as a unified environment shared between all devs, a faster onboarding process for new members, and predictable deployments. For example, in my previous article ",s.createElement(t.a,{href:"/blog/microservices-vs-monolith-architecture"},"âMicroservices vs Monolith architectureâ"),", I made the point that with microservices you have to use Docker, because otherwise youâre launching multiple microservices on a local machine and development becomes a huge pain. When you have even 5â10 microservices, you run them through your terminal one by one and have to make sure that you have all dependencies, db, elasticsearch, etc., installed. Alternatively, you can get it running with one command using docker-compose, a much better approach."),"\n",s.createElement(t.p,null,"But that approach requires you to understand Docker and to not miss the functionality or experience you had without it. One of the things to understand is how to debug within the Docker container. In this article, we will go through a few use cases related to debugging a\nNode.js app in a docker container."),"\n",s.createElement(t.h2,{id:"prerequirements"},s.createElement(t.a,{"aria-hidden":"true",tabIndex:"-1",href:"#prerequirements"},s.createElement(t.span,{className:"icon icon-link"})),"Prerequirements"),"\n",s.createElement(t.ul,null,"\n",s.createElement(t.li,null,"VS Code"),"\n",s.createElement(t.li,null,"Docker"),"\n",s.createElement(t.li,null,"Docker extension for VS Code"),"\n"),"\n",s.createElement(t.h2,{id:"cases"},s.createElement(t.a,{"aria-hidden":"true",tabIndex:"-1",href:"#cases"},s.createElement(t.span,{className:"icon icon-link"})),"Cases"),"\n",s.createElement(t.ul,null,"\n",s.createElement(t.li,null,"Node.js, Docker, without Nodemon"),"\n",s.createElement(t.li,null,"Node.js, Docker, Nodemon"),"\n",s.createElement(t.li,null,"Node.js, Docker with docker-compose"),"\n"),"\n",s.createElement(t.h2,{id:"nodejs-docker-without-nodemon"},s.createElement(t.a,{"aria-hidden":"true",tabIndex:"-1",href:"#nodejs-docker-without-nodemon"},s.createElement(t.span,{className:"icon icon-link"})),"Node.js, Docker, without Nodemon"),"\n",s.createElement(t.p,null,"If you already have the Node.js app your Dockerfile, it probably looks like this:"),"\n",s.createElement(a.Code,{codeConfig:i,northPanel:{tabs:[""],active:"",heightRatio:1},files:[{name:"",focus:"",code:{lines:[{tokens:[{content:"FROM node:10-alpineEXPOSE 3000WORKDIR /usr/src/appCOPY package*.json ./",props:{}}]},{tokens:[{content:'RUN npm installCOPY . .CMD [ "npm", "start" ]',props:{}}]}],lang:"text"},annotations:[]}]}),"\n",s.createElement(t.p,null,"In order to continue, we need to build our Dockerfile. I recommend using the VS Code Docker extension and begin building as shown below:"),"\n",s.createElement(t.span,{dangerouslySetInnerHTML:{__html:'<span\n class="gatsby-resp-image-wrapper"\n style="position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 696px; "\n >
1\n <span\n class="gatsby-resp-image-background-image"\n style="padding-bottom: 59.195402298850574%; position: relative; bottom: 0; left: 0; background-image: url(\'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAYAAABiDJ37AAAACXBIWXMAABYlAAAWJQFJUiTwAAACJklEQVR42pWRS08TURiGazQm/gQXRulcqsRgBQulqIlBTHRhQogxMXWhJCaU2wJDLRWhF1raOsOUdmbohZlOWwMbf4K/7fF0AsqGWBdvzslJviff857Ajdeb3Hyzxci7bW69TXN9bo2rz1e5Nvc3V2aXWUjqLCV3WV5ZFVlhaSlBIpEglUqRTCb9Mx6PE7j/IMxkNEY09oTpx08JT0RQQqPIg6j3REYZkVQKpQoV7YC94j6appPL5ahWq5yentLtdqnVaqTTaQLhsExsOsJMbIbpaJTo1BQT4xPcDYVQFAVVVQkGg2TyBXTjkFK5jKbrFM/AnU6HdruN67hks1kCY2MKkcgjJiejIlOEww8FSP0TVQ0JoEQ+v0etXkf7rmEYBvrBAWUBN01TwBxOTk4oFAoEZPl8WPFPWVYuBdq27as1Gk0s0zq7N3yg67pkMhkCF4cvyzlQF6qDrY6Ojuj1evT7fTzPwxHA4n6RjY2N/wNWjaroKeOXP4BXKhWazaavnc/n/d/+J/Ci8kBv0F9ddGlbNqZl0Wq1/PdjseXOzs5wG0qSTDaXp1Qqi6Fdmq22UBa63R4dodzpeH6va+vrw29YLuRomFUO9RJOy8IV8dom3rFFzxGdOjbf0ptDbCiAkgB+/GLyWfvJevEHa3tdFrdd4lsO71PHfPjqkbJ/sZiyh1EOIUsS8qstZpddnn2yebnSZDxe5868gbRgEJzXCS7Uuf0iyW+XP+nfH/OUrwAAAABJRU5ErkJggg==\'); background-size: cover; display: block;"\n ></span>\n <picture>\n <source\n srcset="/static/335f643529d472fd31fbba849e915617/09400/node1.webp 174w,\n/static/335f643529d472fd31fbba849e915617/3266f/node1.webp 348w,\n/static/335f643529d472fd31fbba849e915617/657d2/node1.webp 696w,\n/static/335f643529d472fd31fbba849e915617/f7244/node1.webp 942w"\n sizes="(max-width: 696px) 100vw, 696px"\n type="image/webp"\n />\n <source\n srcset="/static/335f643529d472fd31fbba849e915617/88093/node1.png 174w,\n/static/335f643529d472fd31fbba849e915617/91d18/node1.png 348w,\n/static/335f643529d472fd31fbba849e915617/871fd/node1.png 696w,\n/static/335f643529d472fd31fbba849e915617/1995d/node1.png 942w"\n sizes="(max-width: 696px) 100vw, 696px"\n type="image/png"\n />\n <img\n class="gatsby-resp-image-image"\n src="/static/335f643529d472fd31fbba849e915617/871fd/node1.png"\n alt=""\n title=""\n loading="lazy"\n decoding="async"\n style="width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"\n />\n </picture>\n </span>'}}),"\n",s.createElement(t.p,null,"To enable the debugger in Node.js, we need to use â inspect or â inspect-brk, but because our app will be launched inside Docker, we also need to allow access from external networks to our debugger by passing 0.0.0.0."),"\n",s.createElement(a.Code,{codeConfig:i,northPanel:{tabs:[""],active:"",heightRatio:1},files:[{name:"",focus:"",code:{lines:[{tokens:[{content:'"scripts"',props:{style:{color:"var(--shiki-token-string)"}}},{content:": {",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "start"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"node --inspect=0.0.0.0 index.js"',props:{style:{color:"var(--shiki-token-string)"}}}]},{tokens:[{content:" },",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:"",props:{style:{color:"var(--shiki-token-embed)"}}}]}],lang:"json"},annotations:[]}]}),"\n",s.createElement(t.p,null,"Now, when you execute ",s.createElement(t.code,null,"npm start")," it will run the node debugger on a separate port (by default 9229) you can then connect your debugger tool to. To access debugger, you have to also expose the 9229 port to your host machine. You could do it with the following command:"),"\n",s.createElement(a.Code,{codeConfig:i,northPanel:{tabs:[""],active:"",heightRatio:1},files:[{name:"",focus:"",code:{lines:[{tokens:[{content:"docker ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:"run --rm -d -p 3000:",props:{style:{color:"var(--shiki-token-string)"}}},{content:"3000 ",props:{style:{color:"var(--shiki-token-constant)"}}},{content:"-p 9229:",props:{style:{color:"var(--shiki-token-string)"}}},{content:"9229 ",props:{style:{color:"var(--shiki-token-constant)"}}},{content:"-v",props:{style:{color:"var(--shiki-token-string)"}}},{content:" ${",props:{style:{color:"var(--shiki-token-embed)"}}},{content:"PWD",props:{style:{color:"var(--shiki-color-text)"}}},{content:"}",props:{style:{color:"var(--shiki-token-embed)"}}},{content:":/usr/src/app -v /usr/src/app/node_modules example:latest",props:{style:{color:"var(--shiki-token-string)"}}}]}],lang:"bash"},annotations:[]}]}),"\n",s.createElement(t.p,null,"With that command, we expose 3000 and 9229 ports of the Dockerized app to localhost, then we mount the current folder with the app to /usr/src/app and use a hack to prevent overriding of node modules from the local machine through Docker."),"\n",s.createElement(t.p,null,"Now we could configure with the VS Code wizard debug launch task. Press CMD(Ctrl)+Shift+P(Command Palette) and find âDebug: Open launch.jsonâ:"),"\n",s.createElement(t.span,{dangerouslySetInnerHTML:{__html:'<span\n class="gatsby-resp-image-wrapper"\n style="position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 696px; "\n >
1\n <span\n class="gatsby-resp-image-background-image"\n style="padding-bottom: 32.758620689655174%; position: relative; bottom: 0; left: 0; background-image: url(\'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAYAAAAIy204AAAACXBIWXMAABYlAAAWJQFJUiTwAAAA90lEQVR42o3QwVLDIBQFUD7B6E6rU02AEFJDSCCEZLKwutGqG///V668WHeO7eLMgwEuD1g/jOj8kAT0Rz6McIk/S4BL5/0QYDoH9rB84m46YDu/Y7t84Da+4cLscWlfkLXPJ+yR+QOu4hey5Dq8gnXzE8y4oAkLdB9RuymZIduQ5hPutcUNr7ERu7/JRwgbofyCfNeBxdTy4BysMai1hq4UlBQoBV+r5Dwp/pFD5D94wmKc4JyHMS3a1kLrGnnBwblAcaynNI1B3zuUpQIL9LHpUymMFqUsIYQ8K+iXUgpVpdcxozBKpy4p1Npuvenc7gjtp5dRI98GjNTeuZWTBwAAAABJRU5ErkJggg==\'); background-size: cover; display: block;"\n ></span>\n <picture>\n <source\n srcset="/static/565aa62749b86fcb346455a37647d084/09400/node2.webp 174w,\n/static/565aa62749b86fcb346455a37647d084/3266f/node2.webp 348w,\n/static/565aa62749b86fcb346455a37647d084/657d2/node2.webp 696w,\n/static/565aa62749b86fcb346455a37647d084/e644e/node2.webp 1044w,\n/static/565aa62749b86fcb346455a37647d084/b007b/node2.webp 1214w"\n sizes="(max-width: 696px) 100vw, 696px"\n type="image/webp"\n />\n <source\n srcset="/static/565aa62749b86fcb346455a37647d084/88093/node2.png 174w,\n/static/565aa62749b86fcb346455a37647d084/91d18/node2.png 348w,\n/static/565aa62749b86fcb346455a37647d084/871fd/node2.png 696w,\n/static/565aa62749b86fcb346455a37647d084/4e07d/node2.png 1044w,\n/static/565aa62749b86fcb346455a37647d084/496e3/node2.png 1214w"\n sizes="(max-width: 696px) 100vw, 696px"\n type="image/png"\n />\n <img\n class="gatsby-resp-image-image"\n src="/static/565aa62749b86fcb346455a37647d084/871fd/node2.png"\n alt=""\n title=""\n loading="lazy"\n decoding="async"\n style="width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"\n />\n </picture>\n </span>'}}),"\n",s.createElement(t.p,null,"Then choose Docker: Node.js:"),"\n",s.createElement(t.span,{dangerouslySetInnerHTML:{__html:'<span\n class="gatsby-resp-image-wrapper"\n style="position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 696px; "\n >
1\n <span\n class="gatsby-resp-image-background-image"\n style="padding-bottom: 21.839080459770116%; position: relative; bottom: 0; left: 0; background-image: url(\'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAECAYAAACOXx+WAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAjklEQVR42o3MSw6CMACEYY4g6gp3FLC1isGC9A00MS69/2nGgh6giy//ZjKZtB5+DjB+gl8ClHUYpMJT6a39KJOs27YTyEinQccJbJxjZ9S9AxEWzTChEg4FE4l6FLSLh/oNHj4o5QsnsSDnBvurweFmt+ZcJ9lFRy6RPe4tVg0pQasKrP6hfyzRJTqTEl80tXotbiMRSQAAAABJRU5ErkJggg==\'); background-size: cover; display: block;"\n ></span>\n <picture>\n <source\n srcset="/static/47fa674b073652f0fb1766e8ea34f1ac/09400/node3.webp 174w,\n/static/47fa674b073652f0fb1766e8ea34f1ac/3266f/node3.webp 348w,\n/static/47fa674b073652f0fb1766e8ea34f1ac/657d2/node3.webp 696w,\n/static/47fa674b073652f0fb1766e8ea34f1ac/e644e/node3.webp 1044w,\n/static/47fa674b073652f0fb1766e8ea34f1ac/31c43/node3.webp 1206w"\n sizes="(max-width: 696px) 100vw, 696px"\n type="image/webp"\n />\n <source\n srcset="/static/47fa674b073652f0fb1766e8ea34f1ac/88093/node3.png 174w,\n/static/47fa674b073652f0fb1766e8ea34f1ac/91d18/node3.png 348w,\n/static/47fa674b073652f0fb1766e8ea34f1ac/871fd/node3.png 696w,\n/static/47fa674b073652f0fb1766e8ea34f1ac/4e07d/node3.png 1044w,\n/static/47fa674b073652f0fb1766e8ea34f1ac/786d3/node3.png 1206w"\n sizes="(max-width: 696px) 100vw, 696px"\n type="image/png"\n />\n <img\n class="gatsby-resp-image-image"\n src="/static/47fa674b073652f0fb1766e8ea34f1ac/871fd/node3.png"\n alt=""\n title=""\n loading="lazy"\n decoding="async"\n style="width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"\n />\n </picture>\n </span>'}}),"\n",s.createElement(t.p,null,"This will generate a launch.json file with the following content:"),"\n",s.createElement(a.Code,{codeConfig:i,northPanel:{tabs:[""],active:"",heightRatio:1},files:[{name:"",focus:"",code:{lines:[{tokens:[{content:"{",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:" // Use IntelliSense to learn about possible attributes.",props:{style:{color:"var(--shiki-token-comment)"}}}]},{tokens:[{content:" // Hover to view descriptions of existing attributes.",props:{style:{color:"var(--shiki-token-comment)"}}}]},{tokens:[{content:" // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387",props:{style:{color:"var(--shiki-token-comment)"}}}]},{tokens:[{content:' "version"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"0.2.0"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "configurations"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": [",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:" {",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "name"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"Docker: Attach to Node"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "type"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"node"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "request"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"attach"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "port"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:"9229",props:{style:{color:"var(--shiki-token-constant)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "address"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"localhost"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "localRoot"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"${workspaceFolder}"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "remoteRoot"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"/usr/src/app"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "protocol"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"inspector"',props:{style:{color:"var(--shiki-token-string)"}}}]},{tokens:[{content:" }",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:" ]",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:"}",props:{style:{color:"var(--shiki-token-embed)"}}}]}],lang:"json"},annotations:[]}]}),"\n",s.createElement(t.p,null,"The configuration for Docker is to manually attach to the debugger port and map the local root folder to remote in order to keep breakpoints definitions working."),"\n",s.createElement(t.p,null,"Go to the Debug Page at VS code, press the âPlayâ button and enjoy debugging in Docker."),"\n",s.createElement(t.h2,{id:"nodejs-docker-with-nodemon"},s.createElement(t.a,{"aria-hidden":"true",tabIndex:"-1",href:"#nodejs-docker-with-nodemon"},s.createElement(t.span,{className:"icon icon-link"})),"Node.js, Docker, with Nodemon"),"\n",s.createElement(t.p,null,"The small difference comes when we want to use the debugger with nodemon. To start with, your script in package.json will look like this:"),"\n",s.createElement(a.Code,{codeConfig:i,northPanel:{tabs:[""],active:"",heightRatio:1},files:[{name:"",focus:"",code:{lines:[{tokens:[{content:'"start"',props:{style:{color:"var(--shiki-token-string)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"nodemon --inspect=0.0.0.0 src/index.js"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]}],lang:"json"},annotations:[]}]}),"\n",s.createElement(t.p,null,"Then, because nodemon will restart your app on each change, your debugger will lose a connection. When this happens, there is an option ârestart: trueâ, which will cause you to simply attempt to re
1connect to the debugger after each restart."),"\n",s.createElement(t.p,null,"So your launch.json should look like this:"),"\n",s.createElement(a.Code,{codeConfig:i,northPanel:{tabs:[""],active:"",heightRatio:1},files:[{name:"",focus:"",code:{lines:[{tokens:[{content:"{",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:" // Use IntelliSense to learn about possible attributes.",props:{style:{color:"var(--shiki-token-comment)"}}}]},{tokens:[{content:" // Hover to view descriptions of existing attributes.",props:{style:{color:"var(--shiki-token-comment)"}}}]},{tokens:[{content:" // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387",props:{style:{color:"var(--shiki-token-comment)"}}}]},{tokens:[{content:' "version"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"0.2.0"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "configurations"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": [",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:" {",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "name"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"Docker: Attach to Node"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "type"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"node"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "request"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"attach"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "port"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:"9229",props:{style:{color:"var(--shiki-token-constant)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "address"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"localhost"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "localRoot"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"${workspaceFolder}"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "remoteRoot"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"/usr/src/app"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "protocol"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:'"inspector"',props:{style:{color:"var(--shiki-token-string)"}}},{content:",",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:' "restart"',props:{style:{color:"var(--shiki-token-constant)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:"true",props:{style:{color:"var(--shiki-token-operator)"}}}]},{tokens:[{content:" }",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:" ]",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:"}",props:{style:{color:"var(--shiki-token-embed)"}}}]}],lang:"json"},annotations:[]}]}),"\n",s.createElement(t.p,null,"Go to Debug Page at VS code, press the âPlayâ button and, just as before, enjoy debugging in Docker."),"\n",s.createElement(t.span,{dangerouslySetInnerHTML:{__html:'<span\n class="gatsby-resp-image-wrapper"\n style="position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 658px; "\n >
1\n <span\n class="gatsby-resp-image-background-image"\n style="padding-bottom: 79.88505747126436%; position: relative; bottom: 0; left: 0; background-image: url(\'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAABYlAAAWJQFJUiTwAAABpUlEQVR42q2Ty4rbQBBF9Sljy3YgkVpSv0ZqvcaypEUcvDUBE5gEDIYss/LGkA/xr95U19hZJAyZYC8uXWpVne56dPCj6/Hzc44v33OIbzVq61BWJcqSVJBdOjhXoHQv61XX/aIoXnxJVVUhyI1FUzkYq/A+/oA0SZCmGUQikFiJONVI9SMSZXn1EmTH0kIpDWsMoiiCEAmvQdO2eH7+iiJ3mE5CSKlgtEUUx4hahUjlqJYjtGthqye4px6mbCEeKzRth2EYERMsyySm0xCBo1S6roOhk/I8x3K5xDiO6PsBPZXDWMvO/qBMSpK62KQsI1tSRik+rj9x2oHf9DCl1B/AHqvViv/JS6D3UVKyzd+XPQ8cKMYfFHjqdrtl+mQyZT08TFjeDsMZZrP5P3WNC3xn/E38TReLd39pPl+8Sd43DKmGWuvfKb81+DUxsK5r7Pd7aG3uA7TUxXEcuMj/k+KrQJ+qb8i1hjcDd7sdzuczDejAg3kLlIHr9Rqn04nn7y5AIQRBFkjoDd8l5c1mg+PxiKZpeYhvBvpndjgcuDF+4m8F/gKP8uyuPSpepAAAAABJRU5ErkJggg==\'); background-size: cover; display: block;"\n ></span>\n <picture>\n <source\n srcset="/static/0bda452499027cbac1aa66b00b66c71f/09400/node4.webp 174w,\n/static/0bda452499027cbac1aa66b00b66c71f/3266f/node4.webp 348w,\n/static/0bda452499027cbac1aa66b00b66c71f/21dc7/node4.webp 658w"\n sizes="(max-width: 658px) 100vw, 658px"\n type="image/webp"\n />\n <source\n srcset="/static/0bda452499027cbac1aa66b00b66c71f/88093/node4.png 174w,\n/static/0bda452499027cbac1aa66b00b66c71f/91d18/node4.png 348w,\n/static/0bda452499027cbac1aa66b00b66c71f/0248a/node4.png 658w"\n sizes="(max-width: 658px) 100vw, 658px"\n type="image/png"\n />\n <img\n class="gatsby-resp-image-image"\n src="/static/0bda452499027cbac1aa66b00b66c71f/0248a/node4.png"\n alt=""\n title=""\n loading="lazy"\n decoding="async"\n style="width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;"\n />\n </picture>\n </span>'}}),"\n",s.createElement(t.h2,{id:"nodejs-docker-with-docker-compose"},s.createElement(t.a,{"aria-hidden":"true",tabIndex:"-1",href:"#nodejs-docker-with-docker-compose"},s.createElement(t.span,{className:"icon icon-link"})),"Node.js, Docker, with docker-compose"),"\n",s.createElement(t.p,null,"A third option is to run your docker images with docker-compose, which is good if your service also requires a database or other dependencies you can run with Docker."),"\n",s.createElement(t.p,null,"Create a docker-compose.yaml in your app folder with the following content:"),"\n",s.createElement(a.Code,{codeConfig:i,northPanel:{tabs:[""],active:"",heightRatio:1},files:[{name:"",focus:"",code:{lines:[{tokens:[{content:"version",props:{style:{color:"var(--shiki-token-string)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:"'3'services",props:{style:{color:"var(--shiki-token-string)"}}},{content:":",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:" example-service",props:{style:{color:"var(--shiki-token-string)"}}},{content:":",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:" build",props:{style:{color:"var(--shiki-token-string)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:".",props:{style:{color:"var(--shiki-token-constant)"}}}]},{tokens:[{content:" volumes",props:{style:{color:"var(--shiki-token-string)"}}},{content:":",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:" - ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:".:/usr/src/app",props:{style:{color:"var(--shiki-token-string)"}}}]},{tokens:[{content:" - ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:"/usr/src/app/node_modules",props:{style:{color:"var(--shiki-token-string)"}}}]},{tokens:[{content:" ports",props:{style:{color:"var(--shiki-token-string)"}}},{content:":",props:{style:{color:"var(--shiki-token-embed)"}}}]},{tokens:[{content:" - ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:"3000:3000",props:{style:{color:"var(--shiki-token-string)"}}}]},{tokens:[{content:" - ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:"9229:9229",props:{style:{color:"var(--shiki-token-string)"}}}]},{tokens:[{content:" command",props:{style:{color:"var(--shiki-token-string)"}}},{content:": ",props:{style:{color:"var(--shiki-token-embed)"}}},{content:"npm start",props:{style:{color:"var(--shiki-token-string)"}}}]}],lang:"yaml"},annotations:[]}]}),"\n",s.createElement(t.p,null,"We used basically the same instructions as we used for non docker-compose solution, just converted them in yaml format. Now you can continue with the launch.json file using nodemon or the node.js running option and use Debugger as described
1in previous sections."))}var l=function(e){void 0===e&&(e={});const{wrapper:t}=Object.assign({},(0,n.RP)(),e.components);return t?s.createElement(t,e,s.createElement(c,e)):c(e)};function p(e,t){throw new Error("Expected "+(t?"component":"object")+" `"+e+"` to be defined: you likely forgot to import, pass, or provide it.")}var d=o(2532),k=o(1021),h=o(545),m=o(9072),b=o(3669),g=o(9063),u=o(352),y=o(84);const v=e=>{let{data:{mdx:{author:t,frontmatter:o,fields:{slug:n}},allMdx:{nodes:r}},location:a,pageContext:{videoCovers:i},children:c}=e;return s.createElement(g.A,{headerTheme:"black",headerShowThemeButton:!0},s.createElement("article",{className:"safe-paddings pt-32 sm:pt-24"},s.createElement("div",{className:"container"},s.createElement("div",{className:"relative mx-auto max-w-[696px] xl:mx-0 xl:flex xl:max-w-none xl:justify-center xl:space-x-20 lg:space-x-8 md:block md:space-x-0"},s.createElement("div",{className:"xl:max-w-[696px] lg:max-w-[626px] md:max-w-none"},s.createElement(h.A,Object.assign({},o,{slug:n})),s.createElement(k.A,{content:c,videoCovers:i})),s.createElement(m.A,{author:t,readMorePosts:r,socialShareUrl:a.href})))),s.createElement(b.A,{withTopMargin:!0}))};function f(e){return s.createElement(v,e,s.createElement(l,e))}const w=e=>{let{data:{mdx:{frontmatter:{title:t,summary:o,ogImage:n}}}}=e;const r=(0,d.d)(n);return s.createElement(u.A,y.A.blogPost({title:t,description:o,ogImage:r}))}}}]); 2//# sourceMappingURL=component---src-templates-blog-post-jsx-content-file-path-content-posts-2019-01-08-how-to-debug-node-js-in-a-docker-container-index-md-6f2a3eb01f0b88afbe0d.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.