Categories: DockersJavascript

Docker – Create Javascript Development Environment

This article represents Dockerfile code sample which could be used to create Javascript Development environment. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos.

Following are the key points described later in this article:

  • Javascript Development environment
  • Dockerfile representing JS Development Environment
  • One script used for Images/Containers
Javascript Development Environment

Following tools are installed to make Javascript development environment.

  • NodeJS runtime
  • Typescript compiler
  • Grunt-cli
  • Bower
  • JSHint for code quality check
  • Jasmine for unit tests
Dockerfile representing JS Development Environment

Following dockerfile (nodejs_base.df) could be used to create NodeJS base image and represents NodeJS runtime.

# Use centos6 base image
FROM    centos:centos6

# Enable Extra Packages for Enterprise Linux (EPEL) for CentOS
RUN     yum install -y epel-release

# Install Node.js and npm
RUN     yum install -y nodejs npm

Following Dockerfile (javascript.df) is used to create Javascript Dev Environment image representing following tools:

  • Typescript compiler
  • Grunt-cli
  • Bower
  • JSCS
  • Browserify
  • JSHint for code quality check
  • Jasmine for unit tests
FROM  nodejs_base

# Install Typescript
RUN npm install -g typescript

# Install Grunt CLI
RUN npm install -g grunt-cli

# Install Bower
RUN npm install -g bower

# Install jshint
RUN npm install -g jshint

# Install Browserify
RUN npm install -g browserify

# Install JSCS
RUN npm install -g jscs

# Install Jasmine
RUN npm install -g jasmine

RUN mkdir /spec
RUN mkdir /spec/support

RUN jasmine init
One script used for Images/Containers

Following script (installJS.sh) could be used to create Javascript Dev environment. It includes following:

  • Creation of NodeJS runtime image
  • Creation of Javascript tools image
#!/bin/sh

if [ $# == 0 ]; then
  echo "This script expect container name argument. Example: ./installTS.sh jsdev"
  exit 100
fi

docker stop $1;docker rm $1

# Build NodeJS image if it does not exists
#
nb_image="nodejs_base"
nb_df="nodejs_base.df"
if [ `docker images $nb_image | wc -l` -lt 2 ]; then
  echo "Docker Image $nb_image do not exist..."
  echo "Builing docker image $nb_image"
  if [ -f $nb_df ]; then
    docker build -t $nb_image -f $nb_df .
  else
    echo "Can't find Dockerfile $nb_df in the current location"
    exit 200
  fi
fi

# Build Typescript image if it does not exists
#
js_image="javascript"
js_df="javascript.df"
if [ `docker images $js_image | wc -l` -lt 2 ]; then
  echo "Docker Image $js_image do not exist..."
  echo "Builing docker image $js_image"
  if [ -f $js_df ]; then
    docker build -t $js_image -f $js_df .
  else
    echo "Can't find Dockerfile $js_df in the current location"
    exit 200
  fi
fi

docker run --privileged=true -ti -dP --name $1 -v /c/Users:/mnt/Users $js_image /bin/bash  

 

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking.

Share
Published by
Ajitesh Kumar

Recent Posts

Agentic Reasoning Design Patterns in AI: Examples

In recent years, artificial intelligence (AI) has evolved to include more sophisticated and capable agents,…

3 weeks ago

LLMs for Adaptive Learning & Personalized Education

Adaptive learning helps in tailoring learning experiences to fit the unique needs of each student.…

4 weeks ago

Sparse Mixture of Experts (MoE) Models: Examples

With the increasing demand for more powerful machine learning (ML) systems that can handle diverse…

1 month ago

Anxiety Disorder Detection & Machine Learning Techniques

Anxiety is a common mental health condition that affects millions of people around the world.…

1 month ago

Confounder Features & Machine Learning Models: Examples

In machine learning, confounder features or variables can significantly affect the accuracy and validity of…

1 month ago

Credit Card Fraud Detection & Machine Learning

Last updated: 26 Sept, 2024 Credit card fraud detection is a major concern for credit…

1 month ago