Debugging Nodejs app running inside Docker container via Google Cloud

328 views
Skip to first unread message

Nik Sumeiko

unread,
Feb 14, 2015, 2:57:54 PM2/14/15
to nod...@googlegroups.com
I have found Google provides some guidelines on how to run Nodejs on a custom runtime environment: https://cloud.google.com/solutions/nodejs
Everything seems fine and I am managing to start my Nodejs app on local machine running `gcloud preview app run .`.
As I can see, it probably creates a Docker container and runs Nodejs program in there. I am saying "probably", because it is my first experience with Docker, however I am 2+ years experienced Nodejs developer.

So my question is how to debug (with breakpoint stops) my Nodejs program when it is running inside Docker container? Using Chrome Developer Tools or how can I set up Webstorm debug configuration to make it stop on breakpoints. Is it possible to configure Docker on how it starts node or even start Docker via `gcloud` inside Webstorm to assure debugging is working? Any help or clarifications are appreciated.

Nik Sumeiko


Joaquin Menchaca

unread,
May 26, 2016, 12:18:06 AM5/26/16
to nodejs
No one answered this?  Did you figure anything out? 

I am experimenting with a few ideas, based on Pavel's blog: http://pavelpolyakov.com/2015/12/05/node-js-remote-debug-in-webstorm/

In the node application you can specify some convenience functions, e.g. 

"scripts": {
"start": "node server.js",
"debug": "node --debug=5858 server.js"
},

Afterwards, you can override the runtime command line to specify npm start or npm debug.

If you use docker-compose, you can specify a .env file, a default variable:

MODE=start

Then in your docker-compose.yml

command: npm ${MODE}

Then on the command line you can do MODE=debug docker-compose up -d 

Make sure that you point the default server from localhost to whatever the output of docker-machine ip, if you are on OS X.  If on Linux, then localhost is fine.

Another idea I thought about was to specify a DEBUG_OPTS environment variable, which is an empty string, but if NODE_DEBUG=1, then I set DEBUG_OPTS to be equal to "--debug=5858".  The only way to get programatic functionality in Docker is to use a wrapper script, and bootstrap the wrapper script instead of calling node directly.  Most shops that have to do complex things, seed/migrate an external database or other application orchestration, then wrapper scripts are used.  Otherwise, for simple applications, package.json method is easier.

 - Joaquin
Reply all
Reply to author
Forward
0 new messages