Appcontainers/NodeJS

CentOS 6.8 based Customizable NodeJS 6.2.1 Container – 243 MB – Updated 06/20/2016

This container is built from appcontainers/centos
Any of the examples below can pull off of the Quay registry by putting quay.io/ in the front of the namespace/repository

Description:

JavaScript runtime built on Chrome’s V8 JavaScript engine.

Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js’ package ecosystem, npm, is the largest ecosystem of open source libraries in the world.

Official NodeJS Website:

This container has 2 variants of which are built from appcontainers/centos:6, and appcontainers/debian_jessie respectively. Both base OS’s are slightly modified bare bones CentOS 6.8, and Debian 8 Jessie Minimal Installations. The images reside on both the docker hub as well as the quay registry. If you would prefer to use the images distributed from quay.io, just simply append quay.io to the front of the name-space / repository designation as such in the examples quay.io/appcontainers/centos, and quay.io/appcontainers/debian. Modifications to the minimal installations of the base images can be found by looking at the appcontainers/centos, and appcontainers/debian repositories located below:

Docker Hub: appcontainers/centos
Quay Registry: quay.io/appcontainers/centos
Docker Hub: appcontainers/debian

Its purpose is to get a customizable NodeJS instance up and running with a single or multiple docker run statements, depending on how resilient you want the environment.

NOTE: The following documentation will reference the latest tag, referring to CentOS, if you would like to run Debian instead, just add the tag :debian to the image name instead of using either the default (latest) or :centos.

 

You Tube Demo:

Coming Soon

 

Running the Container:

docker run -d -it --name nodejs -h nodejs -p 3000:3000 appcontainers/nodejs

This example will start a new container named nodejs. The container is simply an environment with both Node and NPM pre installed. The container makes no other dependency assumptions. You can just attach to the running container, Git clone your code, npm install, and npm start to start serving your Application.

Running the container with persistent storage on the /home directory

docker run -d -it \
--name node-data \
-h node-data \
-v /home \
-e TERMTAG DATA \
appcontainers/centos
 
docker run -it \
--restart always \
--name nodejs \
-h nodejs \
-p 3000:3000 \
--volumes-from node-data \
-e TERMTAG NODEJS \
appcontainers/nodejs

This example will start a new container named node-data. It will flag the /home directory as persistent storage. It will then spin up a second container running nodejs, that will map its home directory to the persistent volume located on node-data. You can then just attach to the running nodejs instance, git clone your code into the /home directory and do a npm install / npm start to start serving your Application.

 

Access the new Install:

Simply Navigate to the IP address of the host/container via a standard http or https request after installing your application code. (80/443 default). You also could put a host file entry in mapping the host IP with the configured $APP_NAME, allowing you to hit that URL directly from a browser, or if the container is running locally, then you can hit it via localhost, 127.0.0.1, or by the container IP which can be obtained with a docker inspect nodejs | grep IP.

Once the container is up and running you can attach to the container via docker exec -it nodejs bash or you can copy existing project data from your local machine via docker cp /path/to/your/data nodejs:/home/data. Lastly if a nodejs restart is not convenient, then you can launch the container appending the command /bin/bash to the end of any of the docker run statements above, and then simply attach to the container via docker attach nodejs (hit enter twice), which will make the container act like a standard VM, allowing you to stop and start services normally. When you are finished in either the attached or exceed container, do not type exit (which would shut down the container), but instead use the detach key combination of CTL P + CTL Q.

 

Launching the Container via docker-compose:

Copy the text below and paste it into a file named docker-compose.yml. Then you can navigate to the directory and if you have docker-compose installed, just issue the following command:
docker-compose up -d

NOTE: If you need assistance setting up docker-compose please visit http://www.appcontainers.com to watch the tutorial or read about the installation process.

Centos:

data:
  image: appcontainers/centos
  hostname: node-data
  stdin_open: true
  tty: true
  volumes:
  - /home
  environment:
  - TERMTAG=NODEDATA
  command: sleep 1
 
nodejs:
  image: appcontainers/nodejs
  hostname: nodejs
  stdin_open: true
  tty: true
  restart: always
  ports:
  - "3000:3000"
  volumes_from:
  - data
  environment:
  - TERMTAG=NODEJS
  command: /bin/bash

Debian:

data:
  image: appcontainers/debian
  hostname: node-data
  stdin_open: true
  tty: true
  volumes:
  - /home
  environment:
  - TERMTAG=NODEDATA
  command: sleep 1
 
nodejs:
  image: appcontainers/nodejs:debian
  hostname: nodejs
  stdin_open: true
  tty: true
  restart: always
  ports:
  - "3000:3000"
  volumes_from:
  - data
  environment:
  - TERMTAG=NODEJS
  command: /bin/bash

Ubuntu:

data:
  image: appcontainers/ubuntu
  hostname: node-data
  stdin_open: true
  tty: true
  volumes:
  - /home
  environment:
  - TERMTAG=NODEDATA
  command: sleep 1
 
nodejs:
  image: appcontainers/nodejs:ubuntu
  hostname: nodejs
  stdin_open: true
  tty: true
  restart: always
  ports:
  - "3000:3000"
  volumes_from:
  - data
  environment:
  - TERMTAG=NODEJS
  command: /bin/bash

 

Dockerfile Change-log:

06/20/2016 - Updated to Node 6.2.1
01/12/2016 - Updated to Node 5.4
12/30/2015 - Updated to Node 5.3
08/27/2015 - Rebuilt on CentOS7 with Appcontainers NodeJS RPM
04/29/2015 - Built Node Container.

 

Verification

------------------------
Test Standalone Version
------------------------
 
docker run -it \
--restart always \
--name nodejs \
-h nodejs \
-p 3000:3000 \
-e TERMTAG=NODEJS \
appcontainers/nodejs \
/bin/bash
 
------------------------
Test Standalone Version
(attached to data vol)
------------------------
 
docker run -d -it \
--name nodedata \
-h nodedata \
-v /home \
-e TERMTAG DATA \
appcontainers/centos
 
docker run -it \
--restart always \
--name nodejs \
-h nodejs \
-p 3000:3000 \
--volumes-from nodedata \
-e TERMTAG=NODEJS \
appcontainers/nodejs \
/bin/bash
 
# Run once, remove, run again
docker kill nodejs; docker rm nodejs
 
docker run -it \
--restart always \
--name nodejs \
-h nodejs \
-p 3000:3000 \
--volumes-from nodedata \
-e TERMTAG=NODEJS \
appcontainers/nodejs \
/bin/bash

0 comments