Wednesday, September 6, 2017
Running NodeJS and related tools from a Docker container
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
Its built using:
docker build -t medined/nodejs .
Using the developer user is important because bower cant be used by root. By itself, this container does not look impressive. Some magic is added by the following shell script called node:
#!/bin/bash
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 thats 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.
download file now
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.