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!
1 Answer 1
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
4 Comments
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.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.node --debug=[::]:5858 --debug-brk test.js ? I am able to break on first line this way.Explore related questions
See similar questions with these tags.
FROMinstruction.FROM node:6.9.5for 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