Why Chrome can't inspect nodejs code in Docker container?

in your package.json scripts:

"debug": "nodemon --inspect=0.0.0.0:9229 index.js",

in your docker-compose.yaml:

services:
  service_name:
    command: npm run debug
    ports:
      - 9229:9229

I am not 100% sure on this but I think that mapping the debugger to run on 0.0.0.0 exposes it to your local network meaning that anyone can connect to your machine IP on port 9229 will be able to debug your nodejs server. Beware your nodejs server has access to the filesystem. So do not run production (or development) servers with this ever.


You need node --inspect 0.0.0.0:8000 in container. Container port 8000 is mapped to host port 9229. So you must use localhost:9229 to connect chrome-dev-tools to node-debugger in container.

Details https://nodejs.org/en/docs/guides/debugging-getting-started/