已經過了兩天了,我仍然無法理解這個應該是簡單的事情!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 –