已经过了两天了,我仍然无法理解这个应该是简单的事情!NodeJS使用Docker进行远程调试
我想:
- 创建的NodeJS码头工人群体的服务,并在 调试模式
- 运行的NodeJS揭露代码调试端口主办
- 能够连接从到调试主办
最简单的步骤来重现问题:
[email protected] docker service create --name dbg-nodejs --publish 4444:4444 node sleep 10d
[email protected] containerID=$(docker container ls --filter name=dbg-nodejs | awk 'FNR == 2 {print $1}') ### find the containerId
[email protected] docker exec -d $containerID /bin/bash -c "(echo \"console.log('\n\n\nHello from NodeJS\n\n\n');\" > /usr/test-dbg.js) && node --inspect-brk=4444 /usr/test-dbg.js"
[email protected] docker exec $containerID /bin/bash -c "curl localhost:4444 -v" ### you see the output here! Great the debugging port is working within the container
[email protected] curl localhost:4444 -v ### aaahhhhh <<--- CANNOT CONNECT TO the published 4444 port!!!!!!
发布端口工作正常。如果我使用容器运行一个使用4444的netcat,它就可以正常工作!不知何故节点调试器的行为不同。但它不应该!这只是TCP! :/
更多信息: 因此,如果不是node --inspect-brk=4444 /usr/test-dbg.js
我做netcat -l -p 4444
,事情工作正常。即使用默认的入口网络,我可以从主机连接到容器。不知何故,行为是不同的!他们都是TCP。
我可以按照你所描述的转发端口,但我仍然无法使用WebStorm来远程调试它。您是否在使用WebStorm,或者您是否至少可以将我指向正确的方向?谢谢。 –
增加了一些信息。希望能帮助到你。 – Kasra
真棒谢谢!我得到了铬调试器从此工作。但为了使用WebStorm,我必须将节点降级到版本7.x –