docker-node: Unable to debug node apps in images node:14 to node:16

Environment

  • OS: MacOS Ventura 13.1
  • Browser: Chrome: Version 108.0.5359.124 (Official Build) (x86_64)
  • Docker: Docker version 20.10.17, build 100c701
  • Image tags: Various (see below)
  • Node versions: Various (see below)

Expected Behavior

Able to debug a node application running in docker

Current Behavior

For base images node:14, node:15 and node:16 the debugging session starts but Chrome dev tools is unable to connect.

Steps to Reproduce

Using this simple dockerfile:

FROM node:16
WORKDIR /usr/src/app
COPY --chown=node:node index.js ./
USER node
CMD [ "node", "index.js" ]

where the contents of index.js are only console.log('Hello World!').

docker build -t debug-test . && docker run debug-test

Hello World!

docker build -t debug-test . && docker run -p "9229:9229" debug-test node --inspect-brk="0.0.0.0:9229" index.js

Debugger listening on ws://0.0.0.0:9229/c29fa1e4-0256-44ce-898b-45d7b43c667e

Chrome debugger does not attach.

Changing base image to node:13, node:17, node:18 or node:latest in the dockerfile and re-running the command above results in Chrome debugger attaching.

Additional Information

I’m aware that it is improbable that debugging is broken for all users of these images but I’m at a loss as to what the problem is and why it is for certain images only. I’ve burnt a good day and a half investigating this problem and would really appreciate any pointers as to what might be wrong.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 21 (7 by maintainers)

Most upvoted comments

For clarity, I didn’t replace my localhost entry, instead I added an extra for 127.0.0.1. Should hopefully cover all bases.

😆 Ok that didn’t take long. I stumbled across this issue and tried it’s suggestion of adding 127.0.0.1:9229 to network targets in Chrome, and it worked (while running node:18-alpine). I’ve only ever had localhost wired up (which still works with node:18).

Also, strangely no connections show up with lsof even though I am connected and debugging. I had the DevTools open, but I wasn’t in file system of the server. Once I went in, and ran lsof I got

COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
chrome  184105  nox  169u  IPv4 731373      0t0  TCP localhost:43366->localhost:9229 (ESTABLISHED)

which is what I would expect.