0% found this document useful (0 votes)
12 views

Docker

DOcker Notes

Uploaded by

Sandeep Sappal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Docker

DOcker Notes

Uploaded by

Sandeep Sappal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

What is Virtualization

It is technique of splitting physical resource into as many as logical resources as we want.


Ex CPU, Memory, HDD,SDD etc.
Or
Virtualization is technology that transform hardware into software

Hypervisor
It’s a piece of software or firmware that create and run virtual machine.
A hypervisor is also called a virtual machine manager (VMM).

Type 1 Hypervisors: Native [Bare Metal]


A Type 1 hypervisor runs directly on the host computer’s physical hardware.
These hypervisors are typically faster and more efficient than Type 2 hypervisors, as they:
 Interact directly with the host computer’s CPU, RAM, and physical storage space.
 Bypass the need to go through the OS layer.
 Allocate all available hardware processing power and resources to VMs.
 Provide higher security, as there is nothing in between the hypervisor and host CPU that
a bad actor could exploit.
Because of these reasons, most enterprise-level organizations opt for Type 1 virtualization for
their large-scale, data centre computing needs.
Required Hardware for Type 1 Hypervisors
Type 1 hypervisors often require separate management machines or hardware acceleration
software to manage multiple VMs and the host computer’s hardware. These hypervisors cannot
successfully operate without this technology, as managing VMs and host resources
simultaneously is extremely intensive.

Examples of Type 1 Hypervisors


Common examples of Type 1 hypervisors include:

Citrix Hypervisor (XenServer).


VMware vSphere/ESXi.
Microsoft Hyper-V.
Red Hat Enterprise Virtualization (RHEV).
Kernel-Based Virtual Machine (KVM).

Hypervisor Type-2
Type 2 Hypervisors
While a Type 1 hypervisor runs directly on the host computer’s physical hardware, a Type 2
hypervisor runs as a software layer on top of the operating system of the host computer.
Robust Type 2 hypervisors typically provide:
 An easy setup process, as they do not require separate management machines.
 Streamlined access to a guest OS alongside the primary OS the host computer runs on,
which makes them ideal for end-user productivity.
 Additional toolkits for users to install into the guest OS, which provides enhanced
connections between the guest and the host OS.
However, Type 2 hypervisors are not as secure or efficient as Type 1 due to their deployment.
Because communication between a Type 2 hypervisor and the host’s hardware must pass
through the OS layer, issues such as latency, or a delay in processing requests, can occur.
Examples of Type 2 Hypervisors
Common examples of Type 2 hypervisors include:
 Microsoft Virtual PC.
 Oracle Virtual Box.
 VMware Workstation.
 Oracle Solaris Zones.
 VMware Fusion.
 Oracle VM Server for x86.
 CentOS Virtualization.

The Benefits of Hypervisors
Both Type 1 and Type 2 hypervisors feature many benefits, including:
 Efficiency: VMs can be created instantly using hypervisors, which provides organizations
with higher accuracy and efficiency when allocating resources for complex workloads.
 Adaptability: Type 1 hypervisors allow guest operating systems and their applications to
run on multiple different hardware types, rather than relying on OS-specific devices or
drivers. This is because a hypervisor separates each guest OS from the host computer’s
hardware.
 Agility: The agility of hypervisors is primarily due to their ability to run multiple VMs
using one host computer’s resources—but they also provide agile utilization of physical
servers. For example, a hypervisor provides a more cost-efficient way to run multiple
VMs, rather than using multiple servers to complete the same task.
 Moveability: VMs in hypervisor software are isolated from the physical host computer,
which means they can be moved across multiple servers, if needed. This means IT teams
can easily and seamlessly manoeuvre changing workloads to different localized or
remote virtual servers that feature the required networking, memory, storage, or
processing capabilities.
The Drawbacks of Hypervisors
While an amazing technology, there are a few concerns with hypervisor environments compared
to traditional dedicated servers.
 Resource Overhead: Because hypervisors are the managers of their virtual servers, some
of the resources of the physical server will be used by the hypervisor, so the virtual
servers will not be able to use 100 percent of the resources of the physical servers.
 Learning Curve: Managing servers in a virtual environment is different from a traditional
environment, as you need to learn how to use the hypervisor itself to manage the virtual
servers. This can mean additional training for some technicians.
 Additional Security Concerns: Every piece of hardware and software on your server
represents a possible attack vector for hackers. Adding virtualization can therefore add
security risk through additional attack surface(s).
Hypervisor Type 1 vs. Type 2 in Tabular Form
Hypervisors Containers

Platform Full Operating Systems Independent Applications

Structure Hosted Servers Hosted Applications

Best Uses Infrastructure or Testing Application Development

Hypervisors vs Containers

Docker
Docker Container is like virtual machine

Docker Engine is a tool which creates VM

Testing
Dev Ops
Development Production
Operation

Suppose there are four developers in a team, working on a single project.


Meanwhile one is having a windows system, the second is owing a Linux system & third and
fourth one is working on Mac OS. Now as they are using the distinct environment for creating
single application or software, they will require to carry on things accordance with their
respective machines such as the installation of different libraries and files for their system etc.,
and such situations specially on an organizational and larger level cause numerous conflicts and
problems throughout the entire software development lifecycle. However, the containerization
tools such as docker eliminates this problem.

1] Consistent & Isolated environment create container in isolated manner means each container
have its own OS/tools/development, no container depends on other container. One can create
image of container and share it to another container or other sever or testing team/production
team etc.
2] Rapid Application development take low memory
3] Ensure scalability/flexibility
4] Better potability
5] Cost effective
6] Built in version control system
7] Security
Resource[hdd, ram, CPU] will consume only when container is in working mode, no container
use the H/W & os while they are free or not working.
 Docker is an open-source centralized platform designed to create, deploy and run
application.
 Docker user container on host OS to run applications. At allows applications to use the
same Linux kernel as a system on the host computer rather then creating a whole virtual
OS
 We can install docker on any OS but docker Engine run natively on Linux distribution
 Docker written in Go language.
 Docker is a tool that preforms OS level virtualization also known as containerization.
 Before docker many users face the problem that a particular code is running in the
developer system. But not in the user system.
 Docker was first release in march. 2013, its design by Solomon hyper
 Docker is a set of platforms provide service on user OS level virtualization whereas
VMware use the Hardware level Virtualization
 Docker engine fetch the image from docker hub and install it into container.
Docker engine take 95% of OS from main OS and 5% it will take from docker hub, because all
Linux system have same base-Unix

Even at will share all the H/W resource from main OS.
So container contain any 5% of light weight OS

Advantages
 No pre allocation of RAM
 CI- efficiency – Docker
enable you to build a container image and use that same image across every step
of the development process
 Less cost
 It’s light weight
 It can run on physical H/W virtual H/W or on cloud
 you can reuse the image
 It took very less time to create container.
Note: We never share container we always share image.

Disadvantage
 No solution for data recovery & backup
 Not a cross platform.
 Docker is not a good solution for application require rich UI good for CLI
 Difficult to manage large amount of container
 Docker is suitable when the development OS and testing OS are same if the OS is
different, we should use VM

Architecture of Docker
It contains dependencies
1] when we execute Docker file on Docker Engine It will create image and save it and when we
can create container & install image in it.
2] upload image on Docker hub

Component of Docker

Docker Daemon
 Docker daemon runs on the host OS.
 It is responsible for running container to manage Docker service
 Docker Daemon can communicate with another daemon.
Docker client
 Docker user can interact with Docker through a client
 Docker client uses commands with Docker daemon.
 When a client runs any server command on the Docker client terminal it send the Docker
command to the docker daemon
 It is possible for docker Client to communicate with more than are one daemon

Docker host
Docker host is used to provide an environment to execute & run application. It contains Docker
daemon, images, containers, network & storage

Docker Hub/ Registry


Docker registry manages and store the Docker images.
There are two types of registries in the Docker
1 Private registry: It is used to share images within the enterprise
2 Public registry: also called docker hub

Docker Images

Docker images are the read only binary templates use to create Docker container.
or
Single file with all the dependencies & configuration, required to run a program.

Ways to create images


1 Take images from Docker hub
2 Create images from Docker file
3 Create images from existing Docker container

Docker container
Container hold the entire package that is needed to run the application
OR
In other words, we can say that, the images is a template and the container is a copy of that
template.
Container is like a virtual machine.
Images becomes container when they run on Docker Engine.
Update Linux
yum install -y
Install Docker
yum install docker -y
To check the docker version
docker -v
or
docker –version

To check whether docker daemon is running or not?


service docker status
or
docker info

To run Docker service


service docker start
now if user runs
service docker status
or
docker info
it will show docker service is running
To stop the service
service docker stop
To see all the downloaded docker images
docker images
To check all the running docker container[ps process status]
docker ps
To check all the running & stopped docker containers
docker ps -a

Just Download the image not run it


docker pull jenkins/Jenkins
To create container one can use
1] docker run -it jenkins/Jenkins /bin/bash
2] docker start [name]
docker attach [name]
To remove container
docker rm [name]
To remove images
docker image rm [Imagename]
To search specified images
docker search [imagename]
Docker diff
docker diff [imagename]
compare specified content of container with original container[image]
Docker Commit
Docker commit [imagename] [updated/newimagename]
Use to create new image from existing container
Dockerfile component
Dockerfile (D must be capital) is basically textfile which contains set of instruction to create
Docker container using docker image.
Or
Automation of docker image creation
Components of Dockerfile
FROM <image name>
Use to create container from specified image name
This must be first statement of docker file

RUN <linux command>


This component use to execute given command
MAINTAINER <author name>
Define author name of container
COPY <source> <target>
Use to copy file from source to target
ADD < url/zip>
Use to download file from internet or also use to extract the zip file
EXPOSE
to start server like tomcat ngix etc
WORKDIR <dir>
To set working directory of container by default
CMD <command>
Use to execute command while container creation
ENTRYPOINT <command>
ENTRYPOINT is same as CMD but ENTRYPOINT commands executes before CMD

ENV
To set Environment name of container

ENTRYPOINT
Similar to CMD but has higher priority then CMD, first command will be execute by
ENTRYPOINT only

To create Script
Create a file using
vi Dockerfile
and write following command
FROM ubuntu
RUN echo “this is my first docker script” > data.txt
To run Docker file script
Docker build -t <image name> .
Volumes in Docker
Volumes(folder) shared by all the containers.
If container remove volume never delete.
Two types of sharing
- Container to container
- Host to Container

Properties of volume
- Volume is simply directory inside container
- Firstly, we have to declare the volume and then share the volume
- Even we stop the container, still we can access the volume
- Volume will be created in any one container and further it shared by
Another container.

- We can not create volume in existing container


- You can declare a directory as volume only while creating container
- You can share one volume across any no of container
- Volume will not be included when you update an image
- You can map volume in two ways
Container < - - > Container
Host < -- > Container

Running Container

Volume Create Create


Containers

Volume
Volume

Container Container
One Two
Benefits of Volume

- Decoupling container from storage


- Share data among different containers
- On deleting container volume will not delete

Port Expose in Docker

Mapping EC2 PORT WITH DOCKER


Containers have no IP address
 Create a new container with exposing port
docker run -td --name techtech -p 80:80 ubuntu

Move to the container


- docker exec -it techtech /bin/bash
Difference between Docker attach and Docker exec is that
Docker execute always use to start new process within the container
- Update the ubuntu OS
- apt-get update
Install apache2 http sever
- apt-get install apache2 -y
- service apache2 start
Now install website in folder /var/www/html

How to push docker image in DOCKER HUB

- First of all create your account on dockerhub.com


- Now create a new container

docker run -it ubuntu /bin/bash


- Create docker image
Docker commit <container name> <new image name>
- Now login to docker hub

docker login
it will ask username and password
- Tag the image which you want to upload on docker hub

docker tag <new imagename> username/projectname


- Push the image
docker push username/<projectname>

Some Other Docker Commands


- Docker volume ls
Will show all the volumes with id
- Docker volume rm <volume name>/id
- Docker volume prune
Will remove all the unused volume
- Docker volume inspect id/name
- Docker container inspect id/name
- Docker volume create <volumename>
Create new volume

- docker stop $(docker ps -a -q)


- docker rm $(docker ps -a -q)
- docker rmi -f $(docker ps -a -q)
forcefully remove all the container
EC2-User Host
Machine
DOCKER

Container

HTTP 80 SSH 22

Response Request

You might also like