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

前端 未结 5 1138
再見小時候
再見小時候 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条回答
  •  Happy的楠姐
    2021-02-02 10:45

    There is an easier way, at least from Docker 0.11 or something.

    Run, on your development machine only, Docker with --net="host". This makes Docker bind to the localhost directly, and not creating a bridging network adapter, so the Docker machine runs like any other process on your machine and opens the ports it needs on the local interface.

    This way, you can connect to your debug port as if Node was not running inside Docker.

    More documentation here : https://docs.docker.com/reference/run/

    Before Docker 0.11 you have other two ways of debugging, apart from using node-inspector :

    • Run sshd inside your Docker machine and setup an ssh tunnel, as if you were to debug on a remote machine.
    • "Mess up" with ip-tables to "revert" the Docker mapping of local ports. There is something about it here Exposing a port on a live Docker container .

提交回复
热议问题