Categories: DockersJavascriptWeb

Docker – How to Setup Typescript Development Environment

This article represents code samples on how to get setup with Typescript development environment with Dockers. 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:

  • Build NodeJS & NPM image
  • Build Typescript image
  • Create Typescript container
  • One script to create images & Typescript container
Build NodeJS & NPM Image

Following code can be used to create NodeJS/NPM image.

# Use base image of centos6
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

Place the code in a file and name it as nodejs_base.df. The above code could be used to build the nodejs image using following command:

docker build -t nodejs_base -f nodejs_base.df .
Build Typescript Image

Following code assumes that above image is built with tag “nodejs_base”.

FROM  nodejs_base

RUN npm install -g typescript  

Place the code in a file and name it as typescript.df. The above code could be used to build the typescript image using following command:

docker build -t typescript -f typescript.df .
Create Typescript Container

Once the “typescript” image is built, one could create the container where typescript files could be compiled. Following command could be used to build the typescript container.

docker run -ti -dP --name ts1 -v /c/Users:/mnt/Users typescript /bin/bash

Type “tsc –help” command and it should print the information in relation with tsc and different options.

One Script to Create Node/NPM Image & Typescript Container

Following script could be used to create Typescript container.

#!/bin/sh

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

# 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
#
ts_image="typescript"
ts_df="typescript.df"
if [ `docker images $ts_image | wc -l` -lt 2 ]; then
  echo "Docker Image $ts_image do not exist..."
  echo "Builing docker image $ts_image"
  if [ -f $ts_df ]; then
    docker build -t $ts_image -f $ts_df .
  else
    echo "Can't find Dockerfile $ts_df in the current location"
    exit 200
  fi
fi

docker run --privileged=true -ti -dP --name $1 -v /c/Users:/mnt/Users $ts_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,…

2 months ago

LLMs for Adaptive Learning & Personalized Education

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

3 months ago

Sparse Mixture of Experts (MoE) Models: Examples

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

3 months ago

Anxiety Disorder Detection & Machine Learning Techniques

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

3 months ago

Confounder Features & Machine Learning Models: Examples

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

3 months ago

Credit Card Fraud Detection & Machine Learning

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

3 months ago