Docker With Node.js

Abstract

In this article, we are going to see what is docker container and its usage with real-time examples.

Agenda

  • What is docker
  • What is a docker container
  • What is used for 
  • Installation
  • Create Image
  • Run the docker image in the local machine
  • Push the image into the repository 

What is Docker

Docker is an open-source and container-based platform used to enable developers to create an image that has everything. In earlier days we used to work with virtual machines which run on top of the Hypervisor, so it takes huge memory and VM. However, In this case, docker works with the help of the Docker engine which is a lightweight module. 

What is a docker container?

A docker container is a package of software that has a project and its dependencies as an image. This is a lightweight virtual environment to run the application, which means the image can run on any environment since it has all its pre-requisite and dependency inside the cocker container 

What is used for 

Typically docker is used to working for distributed applications that work effectively with different environments. In case you have multiple microservices created on different tech stacks and each service has its own dependencies. To deploy the whole application into a new environment, In earlier days we suppose to install all dependencies before deploying our project since docker gives a package that reduces this setup time frame and easy to execute anywhere option.

Installation Methodology

In docker, we have two flavors of repositories

  • Public Repository ( Anyone can able to fork it and run it globally)
  • Private Repository ( This package is restricted globally, which means it applies only for internal usage)

Please follow the below steps to install the docker in Chromebook (Debian OS)

  • First signup in DockerHub

    • This is the placeholder to keep our repository images

  • Enable the developer mode on Chromebook and follow the below steps for installation

    • sudo apt-get update
      sudo apt-get install apt-transport-https ca-certificates curl
      gnupg2 software-properties-common -y
      curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
      sudo apt-key fingerprint 0EBFCD88
      sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable”
      sudo apt-get update
      sudo apt-get install docker-ce docker-ce-cli containerd.io -y
    • Now the user is in the docker group

      sudo usermod -aG docker $USER
    • Once done Please use the below command to validate is docker installed on your machine

      • docker --version

    • Test your installation with the help of the below command

      • docker run hello-world

Create an Image Container from the local machine

Once the development is done, create a docker file in your project repository and mention all its dependencies to run the application. For eg., If you running react application, the main dependency is the npm install command. 

Steps to follow 

  1. First Create a docker file and place an entry of all its dependencies
  2. Build it (docker build -t <project-name>)

Run Image as a container in your local machine

docker run <project-name>

Publish the image into the Repository

docker commit
docker push 


Similar Articles