Hey friends welcome back. In this video tutorial series of DevOps
I shall be talking about docker, another important tool used in DevOps
methodology. In the previous video I talked about Kubernetes the link of
which has been given in the description below. Let us look at the agenda of
today's session. We shall discuss about the need of using a docker
what is docker and it's working mechanism different components of docker
difference between virtual machines and docker
then we'll move on and see the use keys on docker and finally hands-on exercise
to create a docker image. So let's begin. Why do we need docker
when a software developer builds an application it works fine with his
computer and environment but when the same piece of software is shared with
another team like operations or testing team they'll face some issues with the
application and this is the most common problem that occurs in the application
industries. This problem occurs mainly because of the difference in the
computing environment. So how this can be resolved before we get into the code
topic let us first understand what is micro services. Micro service
architecture is all about breaking down a large service into various small or
micro services. For example in an organization we will have different
teams namely HR team, finance team, operations teams, sales team, project
management team etc and these small teams work together to form an
organization and these teams can be termed as micro services of that
particular organization. Let us say we have got 5 micro services in an
Operations which requires a host machine and all these 5 micro services require 5
virtual machines which in it's dependencies of that microservice
the resources are not completely used by the micro services in virtual machines
and this problem with virtual machines is a waste of resources and this
resource can be Ram, Disk or processors and this is something when you have got
just five micro processors now think if you have to deal with hundreds of micro
processes and hence the amount of unused space this was the main problem with
virtual machines so what you think how this can be resolved this is certainly
result by using docker so docker is a tool that is used to
create deploy and run applications using docker containers these containers are
used as alternatives to virtual machines and are of lightweight as you can see
docker uses host operating system and docker engine is placed on the host
operating system. Docker containers are formed with the help of docker engine
which includes applications and it's dependencies in it. Docker engine can
have multiple containers on it let us see in the detail how it works
a developer will develop an application which include Coding and the
application requirements and these are stored in a docker file. Docker images
are created using these docker files and this includes the applications and
dependencies of that application. You can also see docker containers in the image
these docker containers are nothing but runtime instances of the docker image
this docker image will be uploaded into docker hub and docker hub acts as a
repository for docker images which includes public and private repositories
with the help of the docker hub the different teams or operations download
the docker image to create their own docker containers based on their
requirement. This resolves the issue of dependencies
and differences in the computing environments which we stated in our
problem statement so in this way the docker delivers an entire package of
applications and dependencies throughout the life cycle of the application. Now
let us move on to docker components. Docker registry; it is a storage of
docker images, these images can be either private or public repositories. Docker
images, these are the read-only templates used to create docker containers it
contains applications and its dependencies you can also create your
own image and upload it on docker hub Docker containers, docker containers are
the runtime instances of docker images it can be built using one or more docker
images. Docker compose; let us say we have multiple applications on various
containers and they are linked to each other so you don't want to execute these
containers one by one and run all at once with one command so in this case
you can use docker compose which runs multiple applications with one single
command. Docker daemon, docker demon Creates and managers docker objects such as
docker image, docker containers. Docker daemon runs on the host machine. Now let
us see the difference between virtual machines and docker containers. Virtual
machines and docker containers mainly differ in three features namely size
startup and integration let us see in detail one by one. When compared to size
you can consider virtual machine as a hippo and docker container as a cat, for
better understanding let us consider an example when you have 14 GB of RAM and
you have to run three virtual machines of 5 GB 5 GB and 4 GB each so your first
virtual machine uses 2 GB second 3 GB and third virtual machine uses 2 GB of RAM
so the total amount of RAM used will be of 7 GB and we are
wasting another 7 GB of RAM which cannot be reused however in the case of docker
CPU will allocate only the required amount of the data that is used for each
docker container like the first application will be allocated 2 GB of
RAM second we'll have 3 GB and third we'll have 2 GB of RAM accordingly and
the total amount of space used will be only 7 GP and you are still left with 7
GB of free RAM so virtual machines takes a lot of time to start up whereas docker
can start up in a few seconds you can compare virtual machines and Dockers as
a cart and jet respectively this is because virtual machine first have to
boot up the host operating system hypervisors and in turn setups different
virtual machines this is because virtual machine first have to boot up the host
operating system hypervisors and in turn setups different virtual machines. This
is time consuming in case of a docker boot time is not required as the docker
containers will be running on your host operating system integration in virtual
machine is possible however it is not a cost effective and makes a complex task
whereas docker is faster cheap and easily scalable and hence apparently
docker containers are more advantageous in comparison with the virtual machines
Did you know BBC news that delivers broadcast and online news in almost 30
languages over 80,000 news items in English alone uses docker
before the adoption of docker BBC used to face problem largely on the speed and
volume it ran more than 26,000 jobs in 10 different continuous integration
environments but sequential scheduling resulting in a chronic logjam and a
combined weight and runtime of up to 60 minutes for a job the problem was
resolved by docker which allowed BBC News to eliminate job eight times
it also gave developers of flexible continuous integration environments that
is easy to work with and which allows much greater control over factors as
application architecture. Let us now talk about the companies using docker
according to the data dock report the move to docker is actually being led by
larger companies rather than smaller companies docker is a spotlight partners
are Microsoft, HP enterprises and Alibaba cloud some of the other companies are
Accenture, avanade, cognizant, CSC, CSRA and leidos. Now let us see how to create
a docker environment image so we can check whether any image or docker
container is running or not using the command PS so nothing is running so
let's revisit now how to build a docker image and how to launch it, let us see
that so first you need to build a certain folder called docker codebase or
you name it anything you want just to keep it organized then we also have a
container which has a webserver so for that I have created two files first one
is docker file and the second one is a script so this docker file where we
would be telling what this container should have and what all packages should
we be installing in it and the second one is the script
which launches the services inside the container so these two would allow us to
create a container now let us go back to the docker file so what are the
various syntax let's see that. The most basic syntax which you must begin
with is from. okay the first line, so this form would tell
you which images to use for this container we are using send os7 image so
it will pull it from docker hub and build it okay then we have got
maintainer in the second line this is nothing but a command even level is a
command of what are the versions but these are optional even if you do not
put these two lines it will work but it's a good practice to put at least
maintainer label is not needed okay so you can avoid it
then is run which would run the command when you build the image it will run the command
inside the image and get the image built like what we are telling it you take
send OS and run this command inside it what happens when we run the e/m command
it installs Apache server as we need this Apache server here okay so install
yum install - why and this so this will install the Apache over here then this
syntax what does it do this expose 80 this exposes our open support inside the
docker image why are we exposing this et good because stttp and Apache listens
to 80 code that's why we wrote this then we have got this ad so when you have to
add a certain file inside the container you use this syntax ad and where do you
want to add the file you have to provide the path for that so inside the docker
container I'm keeping this file under slash so this directly goes to the root
of the docker and then we have got the executable permission to this file so
that the script can execute now CMD so cmd stands for the command which will
run inside the container once the container is running not when it is
being built because when we built it we want to just the Apache to be there we
do not want it to run we want it to run when the system is running like when the
docker container is running okay so we keep a shell script to start Apache so
now you must be thinking how do I know what things to be done in where so we
all use template files from docker hub and modified so in that template
whatever is therefore for sent os7 version we can use it and you can see in send
where seven like the computer is you know sent OS seven
so if you go to in a dot B you won't find Apache only networking is there, see
only network is there so according to the distribution you can find out that's
why I am saying what do we do is we go to docker hub and find the images let's
say I need Apache for you know let me just go to docker hub so I need a
apache for Apache cent os 7 docker ok
so there are two places to look for one is the github.com else you can go to the
docker hub so someone has done it and docker hub itself has officially made
this so who is providing all these official images the project itself like
cent OS itself is providing they want people to use cent OS in Docker so they
provided see the Apache image they are providing so I can go and see their
docker files you can get to any version if they have shared that you can see the
Docker files here they do not have shared docker file it doesn't matter you can
directly pull it and it will start working but if someone has got or has
not shared docker file you can find its repo info from github okay so say you
want to go to the github so mostly some owners are liberals they will share the
docker file here so you can directly see those okay now let's try and build one
image okay so the builds index would be very simple which is docker build - d so
that's what I am going to type in here the command which is docker build - T okay
so T is for tagging whatever image you want to build you can tag it with a
certain name just like these persons have named their image according to the
different tags cent OS Apache this is there you know repository name so you
can rename, or share your repository so let's say your repository or project
name is devops grow that's what I'm going to give it the name
okay DevOps grow so say this is your project name then we can give the image
so this is a good practice like given project name or repository name and then
you give your image name likes cent OS Apache okay so let us do that
cent os Apaches our image name so this was the image and then you can also give
a version now this is optional even if you do not give anything so it takes
latest as they tagged so if I don't give any version it will automatically picks
this one the latest one but see if I have a
semantic versioning system just like 1.0.1
or just like other softwares you know software have so let me simply give it
one point zero so let's see if I make it one point zero and I have put a dot
after that dot means these two files will be used present in this current
location to build the image so now this image is built successfully and we have
got our imageable successfully using this docker. okay
so I hope you guys got a clearer idea of how to build an image in this docker now
let us move forward and summarize what we discussed in today's session so we
started with the problem statement and how docker helps in resolving that
problem then we discuss different components of docker and its working
mechanism we also discussed the difference between virtual machines and
docker containers then we saw how BBC is using docker to eliminate their job wait
times and how to create docker images Intellipaat offers DevOps certification
course designed with the help of leading industry professionals to help you learn
the key skills of DevOps tools which includes docker and many other tools I
hope this video was informative for you for any inquiries feel free to contact
us. In the subsequent videos we shall be discussing some other important tool use
in DevOps methodology I hope the video was informative for you please like the
video and if you have any doubt comment below
we shall respond to it at the earliest. Don't forget to subscribe to our channel
for more such informative videos. Do look out for other related videos in our
playlist. For more detailed information visit our website now. Have a great day
and career ahead