DevOps Training
  • DevOps
  • What is DevOps
    • What DevOps Look like
    • Why DevOps Needed
    • DevOps Automation Tools
    • DevOps Principles
  • cloud computing
    • How DevOps links with Cloud Computing
    • What is cloud computing?
      • Platform as a service (PaaS)
      • Infrastructure as a service (IaaS)
      • Software as a service (SaaS)
      • Function as a Service
      • SaaS, PaaS, IaaS
  • Version Control
    • Git as Version Control
      • Setting up Remote Repo
      • Git Hooks
      • github vs gitlab vs bitbucket
      • Quick Recap Git
  • DevOps #01 Continuous Integration
    • Continuous Integration & Continuous Delivery
      • Understanding CI Tools
      • Prerequisite
      • Continuous Integration
      • CI Tools
      • Travis-CI
        • Travis CI with S3
        • Static Site Build S3
        • Beanstalk with AWS CLI
          • Elastic Beanstalk with Travis CI
        • Travis using Code Deploy EC2
          • Github and Code Deploy
          • Travis CI with Code Deploy
      • Gitlab-CI
        • CI Setup for application
        • Gitlab Runners on EC2
        • CI Integration with AWS
          • Deploying App using Gitlab CI
          • Gitlab CI with AWS S3
          • Gitlab CI with ECS
          • CI Integration with EC2
            • Update and Clean Gitlab.yml
        • Install Gitlab on EC2
      • CI/CD using Jenkins CI
        • Jenkins Build on EC2
        • Jenkins Build EC2 Ubuntu
        • Jenkins CI/CD
          • Create a Build Item
          • Create a Build Pipleine
            • Pipeline Using Docker
            • Pipeline Examples
          • Jenkins CI with S3
            • Jenkins CI - S3
          • Jenkins CI with EC2
    • Jenkins CI Cluster Mode
    • AWS Code Pipeline CI/CD
      • AWS CI/CD Tools
        • AWS Code Build
        • AWS Code Deploy to Beanstalk
        • AWS Code Deploy to EC2
        • AWS Pipeline - Example CI/CD
  • Docker
    • Docker
      • Docker for Developers
        • Install and setup
        • Docker Commands
        • Docker Images Container
        • Docker Architecture
    • Docker Demos
      • Node JS Container
    • Docker-compose
      • Using Docker Compose
      • Docker Compose Demo
  • AWS Quick Refresh
    • AWS Quick Recap - Videos
    • AWS Quick Recap
  • AWS Architecture - Lab
    • Application Deployment - 01
    • Application Deployment - 02
    • Application 3 tier Architecture
  • Basic Networking
    • Computer Networking for Beginners
      • Basic of Networking
      • Networking Protocols
      • OSI Model
      • Network address and Host address
      • Subnetting Type
    • Network Architecture
    • Networking Layers OSI Model
    • Internet protocol
      • CIDR and subnetting
        • Examples
      • AWS VPC Subnets
  • VPC and Networking
    • AWS VPC
    • VPC Demo
      • Bastion Host | Jump Server
  • AWS Components
    • AWS Components In Depth
      • AWS Storage
        • AWS EBS
        • AWS Cloudfront
        • AWS S3
      • AWS Compute
        • ECS
        • AWS VPC
          • VPC Components
        • AWS EC2
        • AWS ELB
          • Application Load balancer
            • Example
        • AWS EC2 Auto Scaling
          • Demo
        • AWS Route 53
        • AWS Lambda Serverless
          • AWS Lambda Serverless Computing
  • Assignments
    • Assignment 01-Node JS app on EC2
    • Assignment 02-Node JS with Mysql
    • Assignment-03
  • Microservices
    • Microservices Architecture
      • Docker and Docker-Compose
      • Docker-Compose Example 01
      • Docker-Compose Example 02
      • Hand-on | Building Microservices
    • Architecture Components
  • AWS ECS
    • AWS ECS
      • Introduction of ECS
Powered by GitBook
On this page

Was this helpful?

  1. Docker
  2. Docker Demos

Node JS Container

PreviousDocker DemosNextDocker-compose

Last updated 5 years ago

Was this helpful?

Running the Application without Docker

i. Clone this project:

git clone https://github.com/collins-b/blogpost.git
cd blogpost 

Dockerizing the Application

We’re going to use the project you cloned above. Now, let’s see how to integrate Docker into your existing project.

i. In the root directory, create a file named Dockerfile, if the name does not exist. This is a text document that contains all the commands that a user could call on the command line to assemble an image.

ii. Populate the file with the following contents:

FROM node
ENV NPM_CONFIG_LOGLEVEL warn
RUN mkdir -p /usr/src/app
EXPOSE 3000
WORKDIR /usr/src/app
ADD package.json /usr/src/app/
RUN npm install --production
ADD . /usr/src/app/
ENTRYPOINT ["npm", "start"]

The commands are explained below:

FROM

The base image for building a new image in our case is the node. This command must be on top of the Dockerfile.

ENV

- It defines an environment variable.

RUN

- This is used to execute a command during the build process of the docker image.

ADD

- Copies a file from the host machine to the new docker image.

ENTRYPOINT

- Defines the default command that will be executed when the container is running.

WORKDIR

- This is directive for ENTRYPOINT command to be executed.

EXPOSE

- Exposes a specified port on which the container will run.

Next, run docker build -t web-app . to build a Docker image. Don’t forget to include the period. You can tag your image with any name. Here, I have tagged web-app as shown in the command:

Next, we’re going to create a Docker container by running the created image and by using the command below:

docker run -d -p 3000:3000 web-app

This creates a writeable container layer over the specified image and then starts using the specified command.

I’m using -d flag to run the container in background and print container ID. -p specifies the port in this case and here I’m exposing port 3000.

Docker run

Now is time to check the contents of the created container. This is to prove all the files are in the container.

List the running containers using the command docker ps.

Then, execute into the container by using the container ID and list the files, as shown below:

Run npm install, to install packages, then run npm start. Then visit , where you should see something similar to the below image:

Running the Application without Docker
Docker build
Docker run

Visit to access the application on your favorite browser. Yes, now you have successfully dockerized the application!

Running container
Container shell
http://localhost:3000
http://localhost:3000