It's been two days, and I still can't get my head around this supposed-to-be-simple thing!
I want to:
- Create a nodejs docker swarm service and run the nodejs code in the debugging mode
- Expose the debugger port to host
- Be able to connect to debugger from the host
The simplest steps to reproduce the issue:
root@host docker service create --name dbg-nodejs --publish 4444:4444 node sleep 10d
root@host containerID=$(docker container ls --filter name=dbg-nodejs | awk 'FNR == 2 {print $1}') ### find the containerId
root@host 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"
root@host docker exec $containerID /bin/bash -c "curl localhost:4444 -v" ### you see the output here! Great the debugging port is working within the container
root@host curl localhost:4444 -v ### aaahhhhh <<--- CANNOT CONNECT TO the published 4444 port!!!!!!
The publishing port works fine. If I run a netcat listening to 4444 withing the container, it just works fine! Somehow node debugger is behaving differently. But it shouldn't! It's just TCP! :/
MORE INFO:
So if instead of node --inspect-brk=4444 /usr/test-dbg.js I do netcat -l -p 4444, things work fine. i.e., with the default ingress network, I can connect from host to the container. Somehow the bahavior is different! They are both TCP.