September 30, 2024 10:54 am
Topic starter
Notifications
Clear all
0
Theory of docker and virtualissation
++++++++++++++++++++++++++
Agenda :
-----------
• Servers?
• Types of servers?
• Virtual machines ?
• Difference between virtulization & containerization
• Install docker
• Importatnt terminlogies in docker
------------------------------------------------------------------------------------------
Servers:
-----------
servers are nothing but a computer with high configurations, which will run on Hardware components such as HDD, RAM & CPU's connected via networking components
Types of servers:
-----------------
1. Physical servers:
--------------------
- servers which is setup in your company, which we can see infront of us & which our company can manage.
- physical servers are on-site server that a company must manage and maintain individually inside the company location.
eg: Dataceneters in company, laptop
Physical servers are also called as on-premise servers or data center servers.
disadvantages of Physical servers:
-----------------------------------
• cost of setting up Physical servers is very high
• maintainance:
24X7 Power Supply ==> keep servers under controlled environments.
• optimal usage:
most of hardware resource may go untilized
ex: if we have server with 32 GB RAM, 8cpus & 1000 GB HDD & if our application use a maximum of 20GB RAM, 4cpu's & 250 GB HDD remaining resources goes un-utilized
2. What are Virtual machines or Virtual servers?
- hardware components / servers which you may not see infront of you, but still we can access those virtually
eg: servers provided by cloud providers like AWS (ec2 instances) , Azure , gcp
Hypervisers:
------------
Using hypervisors software we can create Virtual machines.
using hypervisors softwares Any bigger servers can be split into several smallers servers called as virtual machines & this process is known as server virtualization.
Where will Virtual machines get hardware components from?
---------------------------------------------------------
From host servers on which hypervisors software installed on
eg of Hyperviser softwares: Microsoft Hyper-v , Orcale virtual box , VmWare EsX etc...
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
What are Virtual machines or Virtual servers?
----------------------------------------------
- hardware components / servers which you cannot see infront of you, but still we can access those virtually
eg- ec2 instances, all cloud provided servers
What are drawbacks of Virtual machines?
--------------------------------------
- It is old method
- In Virtualization we need fixed allocation of harware resources, which will reduce overall system performance.
- If we use multiple guest OS (or) Virtual machines then the system performance is low.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Note:
=====
1. interchangebale names or other names for a server
------------------------------------------------------------------------
Servers ==computers== machines == virtual machines <vm> == nodes == slave ==instances ====> all are same
2. interchangebale names or other names of artifacts
--------------------------------------------------
artifacts== packages== binaries ==executables=====> all are same
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Docker
========
Docker is a containerization tool.
-----------------------------------
containers are like virtual machines
Docker is a tool. It is used to create the containers
what is Virtualization?
-----------------------
process of creating VM's from host server is called as Virtualization
• in Virtualization we need to do Fixed allocation of harware resources.
• in Virtualization Guest OS will have more size (size will be in GB's)
what is Containerization?
--------------------------
process of creating containers from host server is called as Containerization
• in Containerization there is no concept of Fixed Hardware resources allocation.
• in Containerization Guest OS will be very small in size (size will be in MB's).
Why containers OS (Guest OS) will be very small in size ?
---------------------------------------------------------
because containers works on Process isolation technology (Need for full os version is removed) containers will use somepart of Host OS
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How to install docker ?
-- Create Ubuntu virtual Machine on AWS
security group ==> inbound rules ==> All Traffic & anywhere
Connect using git bash
Go to Root Account
$ sudo su -
1.download shell script to install docker.
curl -fsSL https://get.docker.com -o get-docker.sh
2.execute shell script to install docker.
sh get-docker.sh ( This will execute the shell script, which will install docker )
How to check the docker is installed or not?
# docker --version
We should be comformatable with three terms
---------------------------------------------------------------
1) Docker Images:
- Docker images are like template files, which will be used to create containers.
- Docker images contains binaries / libraries which are necessary for one software application.
2) Docker Containers:
- Running instance of docker image is called as container.
- Container is nothing but it is a virtual machine, which have very small sized OS
- With the help of images container will run
3) Docker Host:
- Machine on which docker is installed, is called as Docker host.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How to create a containers?
==>creating container has two steps
- step1: download docker image of our choice
- step2: run the downloaded docker image, it will create container from the downloaded image
ex: create a container named as c1 from amazonlinux image
step1: download amazonlinux image:
syntax: docker pull <image_name>
command: docker pull amazonlinux
step2: run the downloaded amazonlinux image to create container with name as c1
syntax: docker run --name <container_name> <image_name>
command: docker run --name c1 amazonlinux
ASSIGNMENT
-----------------------
********Important_Interview_Question**********************
- what is the Difference between virtual machines & a conatiners ?
Docker
========
Docker is a containerization tool.
-----------------------------------
containers are like virtual machines
Docker is a tool. It is used to create the containers
what is Virtualization?
-----------------------
process of creating VM's from host server is called as Virtualization
• in Virtualization we need to do Fixed allocation of harware resources.
• in Virtualization Guest OS will have more size (size will be in GB's)
what is Containerization?
--------------------------
process of creating containers from host server is called as Containerization
• in Containerization there is no concept of Fixed Hardware resources allocation.
• in Containerization Guest OS will be very small in size (size will be in MB's).
Why containers OS (Guest OS) will be very small in size ?
---------------------------------------------------------
because containers works on Process isolation technology (Need for full os version is removed) containers will use somepart of Host OS
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How to install docker ?
-- Create Ubuntu virtual Machine on AWS
security group ==> inbound rules ==> All Traffic & anywhere
Connect using git bash
Go to Root Account
$ sudo su -
1.download shell script to install docker.
curl -fsSL https://get.docker.com -o get-docker.sh
2.execute shell script to install docker.
sh get-docker.sh ( This will execute the shell script, which will install docker )
How to check the docker is installed or not?
# docker --version
We should be comformatable with three terms
---------------------------------------------------------------
1) Docker Images:
- Docker images are like template files, which will be used to create containers.
- Docker images contains binaries / libraries which are necessary for one software application.
2) Docker Containers:
- Running instance of docker image is called as container.
- Container is nothing but it is a virtual machine, which have very small sized OS
- With the help of images container will run
3) Docker Host:
- Machine on which docker is installed, is called as Docker host.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
How to create a containers?
==>creating container has two steps
- step1: download docker image of our choice
- step2: run the downloaded docker image, it will create container from the downloaded image
ex: create a container named as c1 from amazonlinux image
step1: download amazonlinux image:
syntax: docker pull <image_name>
command: docker pull amazonlinux
step2: run the downloaded amazonlinux image to create container with name as c1
syntax: docker run --name <container_name> <image_name>
command: docker run --name c1 amazonlinux
ASSIGNMENT
-----------------------
*****Important_Interview_Question*************************
- what is the Difference between virtual machine and containers
Docker Commands
==================
Working on Images:
---------------------------
1) To download a docker image
docker pull <image_name>
2) To see the list of docker images
docker image ls
(or)
docker images
3) To delete a docker image from docker host
docker rmi <image_name>
(or)
docker rmi <image_id>
4) To upload a docker image into docker hub
docker push image_name
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Note:
-----
kinds of images which will be available in docker hub are
-----------------------------------------------------------
- OperatingSystem related docker images - (ubuntu, amazonlinux, centos...etc)
- CI-CD tools related docker images - (jenkins, maven, tomcat...etc)
Working on containers:
----------------------------------
5) To create a container from a docker image ( imp )
docker run <image_name>
6) To see the list of all running continers
docker container ls
(or)
docker ps
7) To stop a running container
docker stop <container_name/container_id>
8) To start a stopped container
docker start <container_name/container_id>
9) To see the list of all containers ( i.e. both running and stopped containers)
docker ps -a
10) To delete a stopped container
docker rm <container_name/container_id>
11) To delete a running container forcefully ( i.e. delete directly without stopping)
docker rm -f <container_name/containerid>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
options we can use along in docker run command
----------------------------------------------
syntax: docker run <options_listed_below>
--name ==> Used for giving a name to a container
-d ==> used for running the container in detached mode as a background process
-p ==> Used for port mapping between port of container with the dockerhost port.
-p <portNumber_in_dockerHost>:<portNumber_in_container>
eg- 7070:8080
-it ==> for opening an interactive terminal inside the container
-e ==> Used for passing environment varaibles to the container
-v ==> Used for attaching a volume to the container
--network ==> Used to run the contianer on a specific network
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Example 1: start a tomcat container using image name ==> tomee with container name as c1
syntax: docker run --name <container_name> <image_name>
command: docker run --name c1 tomcat
#observation: this container gets started, it will print logs in our terminal, that is container is running in foreground... to run container in background we need to use -d option in docker run command
Example 2: start a tomcat container using image name ==> tomee with container name as c2 with detached (-d) mode
syntax: docker run --name <container_name> -d <image_name>
command: docker run --name c2 -d tomee
#observation: this container gets started, it will start container in background, as we used -d option in docker run command
Port mapping:
=============
Port mapping enables access to application running inside containers from outside world (i.e internet or browser)
Port mapping also called as port forwarding
Port mapping is needed for Application which needs to be accessed from GUI / browser
eg:- Tomcat, Jenkins etc...
syntax: -p <portNumber_in_dockerHost>:<portNumber_in_container>
How to use Port mapping / port forwarding ?
eg: start a docker container using tomcat image(tomee) with container_name as my_tomcat_container & port forwarding use 7070 port of docker host.
docker run --name my_tomcat_container -p <portNumber_in_dockerHost>:<portNumber_in_container> tomee
docker run --name my_tomcat_container -p 7070:8080 tomee
http:// 3.110.213.91:7070
Scenarios on using docker commands:
------------------------------------
Scenario 1:
----------
Start tomcat as a container and name it as "webserver_container". Perform port mapping and run this container in detached mode
# docker run --name webserver_container -p 7070:8080 -d tomee
To access homepage of the tomcat container
Launch any browser ==> http://public_ip_of_dockerhost:7070
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Scenario 2:
-------------------------
Start jenkins as a container in detached mode , name is as "devserver_container", perform port mapping
docker run --name devserver_container -p <dockerhostPort>:<containerportnumber> -d jenkins/jenkins
docker run --name devserver_container -p 4040:8080 -d jenkins/jenkins
To access home page of jenkins ( In browser) ==> http://public_ip_of_dockerhost:4040
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Scenario 3: Start a container centos_container along with downloanding image simeltaneously
To start centos as container, if centos image ifnot downloaded earlier, then docker will pull that from dockerHub immediately & it will start container
# docker run --name centos_container -it centos
# exit ( To come back to dockerhost )
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
example: To start a container with terminal attached inside the container
syntax: docker run --name <container_name> -it <imagename>
docker run --name c1 -it amazonlinux
# above command apart from creating container c1, it will also open terminal (-it) inside the c1
to come out of this container c1 back to dockerhost we have 2 options
1. exit --> container will gets moved into exited state
2. ctrl p + q --> container will be in running state
Assignment :
-------------------
Note: before starting any assignments clear prevous images & containers
- create a container, container name ==> appserver_container, imagename ==> nginx (default port of nginx is 80) , run in detached mode with port mapping to 5555 on docker host & access nginx from browser
- create a container, container name ==> grafana_container, imagename ==> grafana/grafana (default port of grafana is 3000) run in detached mode with port mapping to 6666 on docker host & access grafana from browser
- create a container, container name ==> atlassian/jira-software (default port of jira is 8080 ) run in detached mode with port mapping to 7777 on docker host & access jira from browser
- create a amazonlinux container with interactive mode & create a environment variable & print variable value inside the container
docker run --name <conatiner_name> -it amazonlinux
What are docker tags?
- Tags contains information about version of a docker image
syntax <imagename>:<tagname>
eg:
1. if you run below command docker will take tag as default tag(i.e latest) even if you dont mention the tag
docker pull amazonlinux
2. if we want to download specific version of image we can mention tag along with image name
to download docker image with tag 2, we can run below command
docker pull amazonlinux:2