Remote NodeJS Debugging in Docker with Visual Studio Code

I would like to use the official docker node image for my application. However, I cannot get the remote debugger to work on the host machine. I am using Visual Studio code to connect to a remote debugger.

The strange thing is to use an informal cusspvz/node image cusspvz/node remote debugger is working correctly.

When I run docker log against an instance of the cusspvz/node 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

What makes me think that the debugger is listening on the wrong IP address (should there be a wildcard, not localhost?)

I tried the built-in debugger as well as nodemon. Unfortunately, I was not able to get the node inspector to work, because it cannot be installed (it seems that the assembly still does not work).

Here is my Docker file:

 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 start the container using 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!

+5
source share
1 answer

By default, node.js (and v8 behind) always use 127.0.0.1 for the debugger. I looked at cusspvz/node and I cannot find anywhere how it provides such a debugger.

It was hard 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
source

Source: https://habr.com/ru/post/1264536/


All Articles