Mega Menu

Wednesday, January 08, 2020

Docker - Build Simple Node JS Webapp docker container

#1 Create the below docker file

 

#2 Create the dependency files

    package.json
    index.js

package.json

   

index.js


 

#3 Build the container

Build the container from the location where all the above 3 files are placed.

 docker build -t testdocker/myfirstweb:v1 .

 

#4 Port binding

 Through the index.js file, we have configured nodeJS to listen to port 8080 i.e; the port 8080 on the container has the app deployed.
To access this port from the local machine, there should be a binding from local machine to docker container, so as to allow the web browser on local machine to access the port 8080 of docker container.
This is done with the help of docker run command.

syntax: docker run -p 8080:8080 testdocker/myfirstweb:v1


#5 Access the test Url from web browser
    http://localhost:8080
         this should print the message
                      Hello My First Web App Container

Screenshots of terminal window and web browser-  

Docker - Docker Image and Container in Simple terms

Simplified explanation based on my understanding of the images and containers.

Docker Image -
           Is a package consisting of the File System Snapshot and Start-Up Command.

Docker Container - 
           Is a process or group of processes with a set of hardware and software resources required to process them.
The resources required can be something like a Kernel, System Process, RAM, HDD, CPU, Installed application.

Eg:

              

Process can be a simple shell script invoking a java class, which will invoke the class file stored on HDD through JVM installed on the same HDD.