Running IronWorker on Docker + Node.js + Windows

docker-nodejs-windows

Exosphere champions best of breed cloud applications. In their own words, “We’ve set out on a mission, a quest if you will, to gather together the best small to medium applications in each class, and try to bolt them together in such a way that combined they form a powerful, user-friendly, complete core small business package.”

For the gnarly job of data synchronization exosphere found few options. Solutions for piping core application data certainly exist, but most vendors lock you down like lawn furniture.  Exosphere found IronWorker appealing, since it saved them the hassle of building their own out of the box solution.

Exosphere is built on a Node.js + Windows development stack. Today, they’ve agreed to let us share their recent post on getting IronWorker + Windows + Node.js humming in unison.

If you’re curious what twists and tweaks are required to get IronWorker going on Windows, read on!


There is an Iron.io quick start project that includes a Node.js example at Github.  This blog post is designed to complement this github project.   When I followed the github examples I came across a few ‘gotchas’ along the way.  So I’ve written this very simple step by step guide on how to create a simple ‘hello world’ project in node.js and get this up and running on Iron.io to help others who may be getting started using these technologies.

You will need an Iron.io account to complete this example, if you don’t have one you can create a trial or a free development account at Iron.io.

Step 1.  Install Node.js

To verify your Node.js installation you can run

node --version

from the command prompt

Step 2.  Install Docker

To validate your Docker install you can run

docker --version

from the command prompt

Step 3.  Create your node.js project

At its simplest a Node.js project is simply a single javascript file.  Create a folder, give it any name you like e.g. you could call it ‘hello_iron’

Tip: For windows users create this folder inside your user folder (C:Users[My User Name]) – the iron docker image seems to expect this location and I had problems when I tried to use another folder

Now create a file inside this folder, call it ‘hello_iron.js’ and enter a single line of code inside this new file

console.log("Hello Iron.io this is Node!");

You can create the javascript code file using a basic text editor such as notepad or notepad ++ or use a dedicated code editor such as atom

So a single line of code is enough to produce a very simple yet fully functional application.  This is one of the strong points of Node.js it has an ‘everything you need and nothing you don’t need’ approach.

Step 4.  Test your Node.js application works

Now run your simple application in Node.js by opening the windows command prompt navigating to the directory you created in step 3 and entering

node hello_iron.js

You should receive the response “Hello Iron.io this is Node!”

Step 5.  Test that your program will work in the Iron.io node environment. 

Iron.io uses Docker images to ensure that code you run on your local machine will work the same way when it runs in the Iron.io environment.  In this example we’ll use the node 4.1 iron Docker image (the latest version available at time of writing).  Open the Docker BASH command shell, navigate to our new directory and enter

docker run --rm  -v "//$PWD":/worker -w //worker iron/node:4.1 node hello_iron.js

Note the double forward slashes – these are required for windows users

You should receive the same response as you did in Step 4, i.e the console will display “Hello Iron.io this is node!”. The fact you get this little message back may seem a bit under-whelming, but what is happening under the hood is pretty cool. You are executing a Node.js application using the same environment that it will use when it runs in production

Step 6  Install the iron client

So far we’ve come a long way.  We’ve installed Node.js, written a simple hello world application and validated it will work in the Iron.io production environment.  The next step is to upload the application to Iron.io.  For this we need the ironcli tool.  This can be installed using

curl -sSL https://get.iron.io/cli | sh

However this did not work for me.  I used the alternate install method  listed in the documentation i.e. download the .exe file directly onto my PC, rename it to iron.exe and enter the path to this executable into my windows PATH environment variable.  You can validate that the iron client has been installed successfully using command

iron --version

Iron will need to know who you are (i.e. your token) and what project you are uploading to. To do this create a file called ‘iron.json’ in the same folder as your javascript file and enter the following

{
    "token": "MY_TOKEN",
    "project_id": "MY_PROJECT_ID"
 }

You can also set these values in your environment variables, using IRON_TOKEN and IRON_PROJECT_ID as the variable names

Step 7.  Upload your Node.js file to Iron.io

Zip up your hello_iron.js file and your iron.json file, and create a zip archive called ‘hello_iron.zip’.  Of course your real application would have many more files and sub folders, the principle is the same, zip up all files and folders that are required.

We now use the ironcli executable we installed int the previous step to upload our zip file to Iron.io  To do this open the windows command prompt, navigate or our new directory and enter

iron worker upload --zip hello_iron.zip --name hello_iron_from_node iron/node:4.1 node hello_iron.js

Validate that your code worker works correctly by logging into Iron.io and running the ‘hello_iron_from_node’ worker task.  You can also use the ironcli client from the command line to queue tasks if you wish.

That’s it!  We’ve created a Node.js hello world application, tested that it works in the Iron.io Docker environment and uploaded it to Iron.io!


Chris Lennon is a passionate technologist, always on the hunt for new ways to do things better. He started exosphereapps.com as vehicle for for sharing that passion. He’s a proud kiwi (New Zealander) and regularly writes about the new wave of technology over on exosphereapps.com.

Leave a Comment





This site uses Akismet to reduce spam. Learn how your comment data is processed.