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!

asked Feb 21, 2017 at 19:27
3
  • 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 Commented Feb 21, 2017 at 20:23
  • Thanks @DerickBailey I'll bear that in mind Commented Feb 22, 2017 at 19:10
  • have you tried this: stackoverflow.com/questions/12440169/… Commented Feb 27, 2017 at 11:41

1 Answer 1

4
+50

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
answered Feb 27, 2017 at 21:12
Sign up to request clarification or add additional context in comments.

4 Comments

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.
@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.
@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.
Yes! That worked :-) thank you ever so much. I've had a lot of pain with this one..

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.