What is Hypervisor?
A hypervisor is computer software, firmware, or hardware that creates and runs virtual machines. A computer on which a hypervisor runs one or more virtual machines is called a host machine, and each virtual machine is called a guest machine.
What is a virtual machine?
A Virtual Machine (VM) is a computing resource that uses software instead of a physical
computer to run programs and deploy apps. ... Each virtual machine runs its own operating
system and functions separately from the other VMs, even when they are all running on the same host.
What is docker?
Docker is an advanced version of virtualization.
The main work of docker is containerization.
keywords of docker are: develop, ship, and run anywhere.
We can run multiple containers on one host, Container does not have any operating system.
Theory about docker
Docker was first released in march 2013, developed by Solomon hykes and Sebastian pahl.
Docker is an open-source centralized platform designed to create, deploy and run applications
Docker uses a container on the host OS, and runs the application. It allows applications to use the same Linux kernel
as a system on the host computer, rather than creating a whole virtual OS
We can install docker-engine on any OS, but the docker engine only runs natively on Linux distributions
Docker is written in the Go language
Docker is a tool that performs OS-level virtualization also called containerization
Before docker, many users faced problems that a particular code is running in the developer's system but not in user's
Docker is a set of platforms as a service that uses OS level virtualization whereas VMWARE uses hardware-level virtualization.
Docker provides a type of platform for our application to be executed.
VMWare virtualization: Hardware Level virtualization
||Kali Linux Container
||OS- Linux, Ubuntu
Advantages of Docker
No pre-allocation of RAM.
Docker enables you to build a container image and use that same image across every steo of the deployment process.
It is light in weight.
It can run on physical hardware/virtual hardware/ or on the cloud.
You can re-use the image.
It took very less time to create container.
Disadvantages of Docker
Docker is not a good solution for application that required rich GUI
Difficult to manage large amount of containers
Docker doesn't provide cross-platform compatability means if an application is designed to run in a docker container on windows, then it can't run on linux or vice-versa.
Docker is suitable when the development OS and testing OS are same if the OS is different, we should use VM.
No solution for data recovery and backup.
Architecture of Docker
Developer creates a Dockerfile - Dependencies & required softwares.
Execute Dockerfile using docker engine, An image will be created using your Dockerfile.
Docker engine will create a container using that image.
If we want to share this image, we can upload it to docker hub(Registry).(just like we store our code on github)
Anyone want to use image can pull the image from docker hub then docker hub will create an image using the image downloaded from docker hub. And then he can use docker to create a container from that image.
Layered file system:
Container does everything in the form of layers.
Components of Docker
Docker Daemon or Docker Server or Docker engine
Docker daemon runs on the Host OS.
It is responsible for running containers to manage docker services.
Docker daemon can communicate with other daemons.
Docker users can interact with docker daemon through a client.
Docker client uses commands and Rest APIs to communicate with the docker daemon.
When a client runs any server command on the docker client terminal, the client terminal sends these commands to the docker daemon.
It is possible for docker client to communicate with more than one daemon.
Docker host(not a part of ecosystem)
Docker host is used to provide an environment to execute and run applications. It contains the docker daemon, images, containers, networks and storages.
Docker registry manages and stores the docker images.
Two types of registry in docker
- Public Registry: Public registry is also called a docker hub.
- Private registry: It is used to share images within the enterprise.
### Docker images
Docker images are the read-only binary templates used to create docker containers.OR a single file with all dependencies and configurations required to run a program.
Ways to create an Image:
- Take image from docker hub
- Create image from Dockerfile
- Create image from existing docker containers
### Docker Container
Container holds the entire packages that are needed to run the application.OR in other words
we can say that the image 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 the docker engine.
Basic commands in docker
To see all images present in your local machine
To find out images in docker hub
$ docker images
To download image from dockerhub to local machine
$ docker search jenkins
If we want to create a container without running it immediately, we can use the Docker Create command below.
$ docker pull jenkins
$ docker container create --name appserver python
To give name to container
To check service is start or not
$ docker run -it --name tush ubuntu /bin/bash
To start container
$ Service docker status
$ service docker start
$ service docker stop
To go inside container
$ docker start tush
To see all containers
$ docker attach tush
To see only running containers
$ docker ps -a
$ docker ps
To stop container
ps - process status
To delete container
$ docker stop tush
$ docker rm tush
What is Dockerfile and create container from it, Components & diff command
Create an image from an existing container
Create one container first
Inside that container do some work, let's create a file inside tmp directory.
$ docker run -it --name tushexample ubuntu /bin/bash
Exit from this container
Now if we want to see the difference between the base image & changes on it then
$ cd tmp/
$ touch myfile
Create image of this container
$ docker diff tushexample
Check our all images
$ docker commit newcontainer updateimage
Create container from our updated image
$ docker images
Check inside this container our file exists or not.
$ docker run -it --name tushnewcon updateimage /bin/bash
$ cd tmp/