Wednesday, October 18, 2023

What Is Docker And Why We Use It


[In Part 1]

1. Docker Problem Statement

2. Installation of Docker on ubuntu

3. What Is Docker Images and Containers

4. Running Ubuntu Image in Container

5. Docker Volume

6. Understand Dockerfile Instruction

7. Docker Networking

        1. Bridge
        2. Host

8. Dockerization of Node.js Application

9. Docker Compose

        1. Services
        2. Port Mapping
        3. Networking

10. Docker Command's Cheat Sheet

======== Docker Real Time Project =============

  • Task 1: Setup Wordpress Project Via Docker
  • Task 2: Setup Java (Reactjs/Nodejs) Project Via Docker
  • Task 3: Setup python (Django/Odoo) Project Via Docker
  • Task 4: Setup PHP (Laravel/Magento) Project Via Docker
  • Task 5: Setup Database (Mongo/Mysql/Postgres) Project Via Docker
  • Task 6: Deploy Docker Container Via Jenkins

======== Docker Real Time Project =============


a) What is Docker ?


  • Docker is a platform designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.



b) When docker is invented and by whom ?

  • Docker was invented by Solomon Hykes. He introduced Docker in 2013 as an open-source project.



c) Why we use Docker ? or Why we need Docker ?

Let's suppose there is a developer who is working on a Nodejs project, and there is a requirement of some application the project.

like Nodejs 18, mongodb 4.4, redis 6.0, and other minor libraries and dependencies with their version.

Now what happens to the same project if after 2 or 3 years someone or the developer has to update the some changes in the project ?
So obviously you will have to setup the same application environment locally just like the first developer did with the same version and then only the project will setup smoothly?
This is fine but the problem is that after 3 years the developer will face problem in setting up the same application version because that version will have become outdated.

this is what Docker solves this environment challenges issue.

Now see what docker will do. Docker will create a container in which the container will contain instructions for the application of the project with the same version.

like

OS : linux
  tools:
     node 18
     mongo 4.4
     redis 6.0
     and other dependencies
 
and developer will run a container then your application will be working well when next someone or developer comes to the same project then the main developer will share the docker file with him.



! END !



























































Monolithic:

  • It is an Architecture. For all Services, if we use one server and one database we can called as monolithic
  • Eg: Ecommerce SAAS application (or) take Paytm App - movie tickets, bookings, etc.., these are called services
  • If all these services are included in one server then it will be called monolithic architecture It is tight coupling i.e. the services highly dependent on each other

Drawback:

  • If one service is down means we have to shutdown entire application to solve that service. So, user is facing problems because it is tightly coupled

Microservice:

  • If every service has its own individual servers then it is called microservices Every microservice architecture has its own database for each service
  • Take same above example. For every service if we keep 1-database, 1-server it is microservice
  • It is loose coupling

Drawback:


  • It is too cost, because we have to maintain so many servers and database. So, maintenance is high When compared microservice to monolithic.
  • Microservice is good to use. Because, if one service is not working. So, we can work on it without shutdown the application. That’s the reason microservices is good and preferable

Why Docker:

  • Let us assume that we are developing an application, and every application has Frontend, Backend and database
  • To overcome the above monolithic architecture we’re using “Docker”
  • So while creating the application we need to install the dependencies to run the code
  • So, I installed Java11, reactJS and MongoDB to run the code. After sometime, I need another versions of java, react and MongoDB for my application to run the code
  • So, it’s really a hectic situation to maintain multiple versions of same tool in our system

To overcome this problem we will use “Virtualization”

Virtualization:

  • It is used to create a virtual machines inside on our machine. In that virtual machines we can hosts guest OS in our machine
  • By using this guest OS we can run multiple application on same machine

=========================Image-1=========================

  • Here, Host OS means our windows machine. Guest OS means virtual machine
  • Hypervisor is also known as Virtual machine monitor (VMM). It is a component/software and it is used to create the virtual machines

Drawback:

  • It is old method
  • If we use multiple guest OS (or) Virtual machines then the system performance is low

To overcome this virtualization, we are using “Containerization” ie., called Docker

Containerization:

  • It is used to pack the application along with it’s dependencies to run the application. This process is called containerization
  • Container:
  • It’s the runtime of the application which is created through docker image Container is nothing but it is a virtual machine, which doesn’t have any OS With the help of images container will run
  • Docker is a tool. It is used to create the containers

=========================Image-2=========================

  • It is similar to virtualization architecture, instead od hypervisor we are having Docker Engine Through Docker Engine we’re creating the containers
  • Inside the container we’re having the application Docker Engine - The software that hosts the container In one container we can keep only image

Docker Image:

  • A Docker image is a file used to execute code in a Docker container.
  • Docker images act as a set of instructions to build a Docker container, like a template. Docker images also act as the starting point when using Docker.
  • (or)
  • It is a template that contains applications, bin/libs, configs, etc., packaged together

Before Docker:

=========================Image-3=========================

  • First, get the code from the GitHub and integrate
  • with Jenkins Integrate maven with Jenkins. So, we
  • get War file
  • So, that war file we have to deploy in different environments
  • So, if you want to deploy war file/application we have to install the dependencies This is the process when docker is not there

After Docker:

=========================Image-4=========================

  • First, get the code from the GitHub and integrate with Jenkins Integrate maven with Jenkins. So, we get War file
  • Here, we’re not going to install dependencies on any server. Because, we’re following
  • containerization rule
  • So, here we’re creating image i.e. image is the combination of application and dependencies image = war + Java+Tomcat+MySql
  • Now, in this image application and dependencies present. So, overall this process is called containerization
  • So, whenever if you want to run your application.
  • Run that image in the particular environment. No need to install again dependencies. Because these are already present in image
  • So, after run the image. In that server that applications and dependencies installed
  • When we run an image, container will gets created. Inside the container we’re having application This images are already prebuilted by docker
  • Container is independent in AMI i.e. If we launch AMI in ubuntu (or) CentOS, any other OS. this container will work

So, overall after docker, In any environment no need to install dependencies. We can just run the images in that particular environment. If container is created means application created

Docker

  • It is an open source centralized platform designed to create, deploy and run applications Docker is written in the GO language
  • Docker uses containers on host OS to run applications. It allows applications to use the same linux
  • kernel as system on the host computer, rather than creating a whole virtual OS
  • Docker is platform independent. i.e. we can install docker on any OS but the “docker engine” runs natively on “Linux” distribution
  • Docker performs OS level virtualization also known as containerization
  • Before Docker, many users face problems that a particular code is running in the developers system but not in the user system
  • Docker is a set of PAAS that use OS level virtualization, where as VMware uses hardware level virtualization
  • Container have OS files but it’s negligible in size compared to original files of that OS

Docker Architecture:

=========================Image-5=========================

We are having 4 components

    1. Docker Client
        a. It is a primary way that many docker users interact with docker. When you use commands such as docker run, the client sends these commands to docker daemon, which carries them out
        b. The docker commands uses the docker API
        c. Overall, here we perform the commands
    2. Docker Host
        a. It contains containers, images, volumes, networks
        b. It is also a server, where we install the docker in a system
    3. Docker Daemon
        a. Docker daemon runs on the host OS.
        b. It is responsible for running containers to manage docker services
        c. Docker daemon communicates with other daemons
        d. It offers various docker objects such as images, containers, networking and storage
    4. Docker Registry
        a. A Docker registry is a scalable open-source storage and distribution system for docker images
        b. It is used for storing and sharing the images
        c. Eg: For git we had GitHub. Same like for docker we had Docker registry

Advantages of Docker:

  • Caching a cluster of containers Flexible resources sharing
  • Scalability - Many containers can be placed in a single host
  • Running your service on network that is much cheaper than standard servers

No comments:

Post a Comment

testing