How to debug Nodejs app running inside Docker container via Google Cloud

前端 未结 5 1077
再見小時候
再見小時候 2021-02-02 10:22

I have found Google provides some guidelines on how to run Nodejs on a custom runtime environment. Everything seems fine and I am managing to start my Nodejs app on local machin

5条回答
  •  无人共我
    2021-02-02 10:33

    If you are using bridge networking for your containers, and you don't want to install node-inspector inside the same container as your node process, I've found this to be a convenient solution:

    • In the main node.js container, map port 5858 to the host
    • Run the main node process with debug enabled
    • Use a separate container for running node-inspector
    • Use host networking for the node-inspector container

    This say, the node-inspector container will connect to localhost:5858 which will then be port mapped through to the main node container.

    If you're running this on a public VM, I'd then recommend:

    • Make sure port 5900 is not exposed publicly (e.g. by the firewall)
    • Make sure the node inspector port (e.g. 8080) us exposed publicly, so you can connect to it

    I wrote a few more details about it here: https://keylocation.sg/our-tech/debugging-nodejs-in-docker-using-node-inspector

提交回复
热议问题