5

I'd like to use the official node docker image for my app. However I cannot get the remote debugger to work on the host machine. I am using Visual Studio Code to connect to the remote debugger.

The strange thing is using an unofficial image cusspvz/node the remote debugger works correctly.

When I run docker log against the cusspvz/node instance of the container I get the following output:

Debugger listening on [::]:5858

However when I run docker log against the node instance of the container I get:

Debugger listening on 127.0.0.1:5858

Which leads me to believe that the debugger is listening on the wrong IP address (should be wildcard rather than localhost?)

I've tried the built in debugger as well as the nodemon. Unfortunately I couldn't get node-inspector to work as it fails to install (appears that the build is failing anyway).

Here is my Dockerfile:

FROM node
WORKDIR /scraper
EXPOSE 5858
ENTRYPOINT ["/bin/bash", "-c", "if [ -z \"$REMOTE_DEBUGGING\" ]; then node --debug index.js; else node --debug-brk index.js; fi"]
COPY . /scraper
RUN npm install

I'm starting the container with docker-compose, using this YML file:

version: '2'

services:
 alt.nphotos.imagescraper:
  container_name: nscraper
  hostname: nscraper
  build:
   context: ./ALT.NPhotos.ImageScraper
   dockerfile: Dockerfile.debug
  environment:
  - REMOTE_DEBUGGING=1
  - AMQP_CONNECTIONSTRING=amqp://guest:guest@nqueue
  ports:
  - "5858:5858"

Any ideas? - TIA!

  • complete side note to you question: you should specify a version number tag with your `FROM` instruction. `FROM node:6.9.5` for example... otherwise, every time you build your image, you'll end up with the latest / newest node version. that sounds good at first, until an unwanted upgrade breaks your code – Derick Bailey Feb 21 '17 at 20:23
  • Thanks @DerickBailey I'll bear that in mind – Adrian Luca Thomas Feb 22 '17 at 19:10
  • have you tried this: http://stackoverflow.com/questions/12440169/how-do-you-debug-a-node-js-server-running-with-chrome-webkit-as-the-remote-debug – Lucas dos Santos Abreu Feb 27 '17 at 11:41

1 Answers1

4

By default node.js (and v8 behind it) always use 127.0.0.1 for the debugger. I've looked at cusspvz/node and I can't find anywhere how it exposes the debugger like that.

It used to be difficult to change this configuration but now you can just use the debug option with an explicit host:

node --debug=[::]:5858 test.js
Debugger listening on [::]:5858
Sébastien
  • 1,015
  • 8
  • 7
  • 1
    Hey, that worked! I did actually try something very similar - with debug-brk and I couldn't get it working which is why I assumed this method wouldn't work either. This is what I saw, any ideas? `Debugger listening on [::]:5858 module.js:563 Debug.setBreakPoint(compiledWrapper, 0, 0); ^ illegal access` However, as you've saved me - I will award the bounty :) Thanks very much. – Adrian Luca Thomas Mar 01 '17 at 18:38
  • @AdrianLucaThomas, I have the same error for debug-brk. Even when using `0.0.0.0` instead of `[::]`. If it's important for you, you can still use `socat` to redirect port. It is a workaround I used previously. – Sébastien Mar 01 '17 at 19:20
  • @AdrianLucaThomas, does it work for you if you combine both? `node --debug=[::]:5858 --debug-brk test.js` ? I am able to break on first line this way. – Sébastien Mar 01 '17 at 19:32
  • Yes! That worked :-) thank you ever so much. I've had a lot of pain with this one.. – Adrian Luca Thomas Mar 02 '17 at 13:26