简体   繁体   English

使用Visual Studio代码在Docker中远程调试NodeJS

[英]Remote debugging NodeJS in Docker with Visual Studio Code

I'd like to use the official node docker image for my app. 我想为我的应用程序使用官方node docker镜像。 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. 我正在使用Visual Studio Code连接到远程调试器。

The strange thing is using an unofficial image cusspvz/node the remote debugger works correctly. 奇怪的是使用非官方图像cusspvz/node远程调试器正常工作。

When I run docker log against the cusspvz/node instance of the container I get the following output: 当我对容器的cusspvz/node实例运行cusspvz/node docker log时,我得到以下输出:

Debugger listening on [::]:5858

However when I run docker log against the node instance of the container I get: 但是,当我对容器的node实例运行docker log时,我得到:

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?) 这让我相信调试器正在侦听错误的IP地址(应该是通配符而不是localhost?)

I've tried the built in debugger as well as the nodemon. 我已经尝试了内置调试器以及nodemon。 Unfortunately I couldn't get node-inspector to work as it fails to install (appears that the build is failing anyway). 不幸的是我无法让node-inspector工作,因为它无法安装(看起来构建失败了)。

Here is my Dockerfile: 这是我的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: 我正在用docker-compose启动容器,使用这个YML文件:

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! - TIA!

By default node.js (and v8 behind it) always use 127.0.0.1 for the debugger. 默认情况下,node.js(以及后面的v8)始终使用127.0.0.1作为调试器。 I've looked at cusspvz/node and I can't find anywhere how it exposes the debugger like that. 我看过cusspvz/node ,我无法在任何地方找到它如何暴露调试器。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM