Developing using Webstorm+Docker+nodejs on OS X and debugging it

First install the latest Docker(I use the Mac version for this tutorial) here: http://docs.docker.com/mac/step_one/

Get Webstorm: https://www.jetbrains.com/webstorm/
Start the Docker Quick start terminal (see screenshot) You’ll start the default docker vm (linux inside OS X).You can find this later by issuing ‘docker-machine ls’:

![] docker-machine ls

Go and download an image inside the docker terminal:Use ‘docker pull ubuntu’

docker pull  ubuntu

To run an interactive shell in the Ubuntu image: use ‘docker run -i -t ubuntu /bin/bash’

docker run -i -t ubuntu /bin/bash

Of course we also want to mount our home directory: e.g. use ‘docker run -it -v $HOME:/mnt ubuntu’ Inside the docker host you can find out that your mount is there: ‘ls /mnt’

ls /mnt

Go and create a folder on the host system that is going to have the app that you want to install for example /Users/thajoust/dev.Create a package.json file by issuing a : ‘npm init’ on the host system in $HOME/dev or create a empty one with: ‘touch $HOME/dev/package.json’ on the host system shell.

touch $HOME/dev/package.json Now if you go to the docker terminal and issue the command ‘ls /mnt/dev/’ you will see the package.son file ls /mnt/dev/ You can exit the container by issuing ‘exit’ in the container shell. You now need to run the docker image from the docker terminal to mount the new directory directly : ‘docker run -it -v $HOME/dev:/testApp -w /testApp ubuntu’

Now you will be in the container and you will be able to see the package.son. You can safely delete it now.docker run -it -v $HOME/dev:/testApp -w /testApp ubuntu

Next up is installing node in the container: First update the package state: ‘apt-get update’ then: ‘apt-get install nodejs’

apt-get install nodejs

Install npm: ‘apt-get install npm’ ![Screen Shot 2015-09-16 at 14.25.19]

apt-get install npm

Install Node locally: ‘npm install n -g’

npm install n -g

First install wget:‘apt-get install wget’

apt-get install wgetthen:Install latest nodejs:‘n latest’n latest

Install express generator:‘npm install -g express-generator’

npm install -g express-generator

Inside your testApp folder you can create an express App:‘express my app’

express myapp

Now we have to introduce a quick workaround for the problem that on some platforms there will be problems with symlinks,.
echo “bin-links=false” >>$HOME/.npmrc

There is now a folder with the name my app, let’s continue:‘cd myapp’ followed by ‘npm install’ (will install all the modules required for running your app) Then it is time to start the app:‘npm start’ Now go to webstorm and open the folder my app

npm startYou will see all the files.Configure the Run/Debug Configuration:Create a Node.js remote Debug using the + on left side cornerHost: 192.168.99.100 Port: 5858Create a Node.js remote DebugExit the docker container and commit it:‘exit’‘docker ps -l’ docker ps -l‘docker commit -m “message” containerId [newNameForTheImage]:[tag]’docker commit -m “message” containerId [newNameForTheImage]:[tag]Now we need to be able to open the ports that the node app is listening (both the app and the debugger):‘docker run -it -v $HOME/dev:/testApp -w /testApp/myapp -p 3000:3000 -p 5858:5858
ubuntu:version1’ docker run -it -v $HOME/dev:/testApp -w /testApp/myapp  -p 3000:3000 -p 5858:5858 ubuntu:version1Run node express app in debug mode:‘node –debug ./bin/www’node –debug ./bin/www

If you go to Webstorm and run the app with your Debug Configuration you will see that all is working.Below is the breakpoint reached when i set it and go to http://192.168.99.100:3000

breakpoint reached