neilm
neilm

Reputation: 356

Issue with node debugging in docker for node:14-alpine and later

I had an issue with not being able to debug a node application running in docker where the dockerfile was based on a tweaked version from an earlier project.

In order to investigate the issue I used a simplified version of the dockerfile:

FROM node:16-alpine

COPY package.json package.json  
RUN npm install

COPY ./index.js .  

CMD ["node", "."]

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

Findings:

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 index.js

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

but the chrome node debugger does not connect.

I tried lots of permutations of ports, docker compose and mounting of code as volumes without any luck.

Also, used this repo to establish that chrome debugger was not broken.

Upvotes: 0

Views: 3517

Answers (1)

neilm
neilm

Reputation: 356

The problem turned out to be the base docker image. The original dockerfile I had copied used node:12-alpine but I tweaked it to be node:16-alpine to match the version of the application I was dockerising. My detective work found that starting from node:14-alpine something has changed to egress which prevents debugging.

Switching the base image from an alpine image to node:16 resolved the problem and allowed debugging of the app running in docker. I'm not clear what the change would have been but if anyone knows I'd be interested.

Upvotes: 2

Related Questions