Node-RED on Docker

03Jan14

Docker is going into the next release of CohesiveFT’s VNS3 cloud networking appliance as a substrate for application network services such as proxy, reverse proxy, load balancing, content caching and intrusion detection. I’ve been spending some time getting familiar with how Docker does things.

Since I’ve also been spending some time on Node-RED recently I thought I’d bring the two activities together as a demo application.

Following in the footsteps of the SSH example I was able to use Oskar Hane’s guide to creating a Node.js Docker.io image and then add in Node-RED[1]. This gave me something that I could run, but not something that was particularly repeatable or malleable.

Having read through Troy Howard’s excellent Where are my Docker images stored? I then set about encoding the steps I’d followed into a Dockerfile:

FROM ubuntu:quantal

RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install python-software-properties python g++ make -y
RUN apt-get install software-properties-common wget unzip -y
RUN add-apt-repository ppa:chris-lea/node.js -y
RUN apt-get update
RUN apt-get install nodejs -y
RUN wget https://github.com/node-red/node-red/archive/0.5.0.zip
RUN unzip 0.5.0.zip -d /opt
RUN cd /opt/node-red-0.5.0 && npm install --production
RUN rm 0.5.0.zip

I broke my normal habit of only using Ubuntu LTS builds here as for some peculiar reason rlwrap, which is needed for Node.js, doesn’t seem to install properly on the Ubuntu 12.04 Docker image.

The nice thing about the way the Dockerfile works is that when things break you don’t have to repeat the preceding steps. Docker just uses its image cache. This makes testing much less painful than in other environments as the cost of making mistakes becomes pretty minimal. This is the key to the power of Docker, and particularly the Dockerfile – the incremental friction between hacking away at the command line and developing a DevOps script has become tiny. It really makes it easy to create something that’s repeatable rather than something that’s disposable.

I also found out that context isn’t preserved from one run command to the next, which is why lines 11 and 12 are like that rather than a more (interactively) natural:

cd /opt
unzip ../0.5.0.zip
cd node-red-0.5.0
npm install --production

Once the Dockerfile built correctly with:

sudo docker build -t cpswan/node-red-0.5.0 .

I could then launch an instance with:

sudo docker run -d -p 1880:1880 cpswan/node-red-0.5.0 \
/usr/bin/node /opt/node-red-0.5.0/red.js

and bring it up in my browser by navigating to http://host_ip:1880

I’ve uploaded the resulting image cpswan/node-red-0.5.0 to the public index if you just want to run it rather than making it.

Note

[1] Perhaps this wasn’t the Docker way to do things. Searching the Docker public image repository turns up an image christened ‘dun‘ Docker, Ubuntu, Node (though it is a few point releases behind on node.js).



2 Responses to “Node-RED on Docker”

  1. You could also use the ‘passenger-docker’ image: ‘A Docker base image for Ruby, Python, Node.js and Meteor web apps’ developed by the Phusion Passenger folks, that has a few other handy features as well.


  1. 1 Ubuntu images on Docker.io | Chris Swan's Weblog

Leave a comment

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