2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018

04/23/2015: Running NodeJS (and related tools) from a Docker container.

In my continuing quest to run my development tools from within Docker containers, I looked at Node today.

The Github project is at https://github.com/medined/docker-nodejs.

My Dockerfile is fairly simple:

FROM ubuntu:14.04

RUN apt-get -qq update \
  && apt-get install -y curl \
  && curl -sL https://deb.nodesource.com/setup | sudo bash - \
  && apt-get install -y nodejs \
  && npm install -g inherits bower grunt grunt-cli

RUN useradd -ms /bin/bash developer

USER developer
WORKDIR /home/developer

It's built using:

docker build -t medined/nodejs .

Using the 'developer' user is important because bower can't be used by root. By itself, this container does not look impressive. Some magic is added by the following shell script called 'node':


CMD=$(basename $0)

docker run \
  -it \
  --rm \
  -p 1337:1337 \
  -v "$PWD":/home/developer/source \
  -w /home/developer/source \
  medined/nodejs \
  $CMD $@

I expose port 1337 because that's the port used on the NodeJS home page example. The current directory is exposed in the container at a convenient location. That location is used at the working directory.

You might be puzzled at the use of $CMD. I symlink this script to bower, grunt, and npm. The $CMD invokes the proper command inside the container.

subscribe via RSS