If you don’t care how I came to write this post and you only care about the meat in the title then scoll down to “setting up the Webstorm project“. Beware that this info was written in the midst of virulent ragnarök and the information might be stale.
wasting time on the old internet
For a research project I am playing around with containerizing a framework for easy deployment. Being a good researcher I set up all the dockerfiles and everything works beautifully. However, I noticed that debugging is quite cumbersome and rebuilding as well as restarting the whole (distributed) system I am working on is annoying. So I wrote myself some shell scripts to automate all the building, stopping and starting of containers away. Nonetheless, this is cumbersome so I thought I set up my IDE (Webstorm) to do these tasks for me. I found a tutorial that looks exactly what I want. “Debugging Node apps in Docker containers through WebStorm” goes through setting up dockerfiles, debugging, etc. and I happily tagged along. Everything worked out — except — the last step where I should connect my debugger to the container port. I could not find the options of Webstorm mentioned by the author. It turns out the internet became old; or rather its’ content became stale. Webstorm became better and also got rid of the functions mentioned in the tutorial. After some looking around I found a small step-by-step explanation by Jetbrains themselves. I probably should have looked at the source from the beginning and avoided wasting time. So I want to provide you with the new new (go and watch Scott Pilgrim now! )way of debugging node.js code inside a docker container in Webstorm.
setting up the Webstorm project
If you are new to Webstorm then you should head over to the original source at Jetbrains as it is a lot more detailed with pretty GIFs to show you exactly how it works. You should check it out in any case if you read this years after I published the following steps. Things might have changed and I don’t want to waste your time as mine was wasted before finding the current solution below.
- Setup your node express project
- Run the project to make sure that the basics work
- In the global Webstorm settings add a docker server (assuming you installed it on your system)
- Connect to your docker server to check that this works
- Edit your (run/debug) configuration and add a remote node.js interpreter of type docker
- Webstorm complains that some settings are missing and we can tell it to auto configure by checking the checkbox — make sure that the automatically filled in infos make sense (This means that the correct source files are being mapped as a volume and that the port mapping is setup so you can actually connect to your container)
- Run your project to make sure your docker server works and you can build images (be patient with this step — it might take some time
- If it is running successfully connect to your express app through your browser or the Webstorm REST client
- Be happy
I hope I could make the internet a little younger again or at least add a drop of up-to-date information to the sea of stale and broken tutorials.
Thank you, your comment successfully submitted
your comment has been submited, it might take a while to be moderated.