Docker allows you to containerize your micro
services and simplify the delivery and management of those micro services. In this video I'll walk
you through what is docker and why to use docker, different docker editions, docker installation,
docker image versus docker container, docker hub and basic docker commands. So first let's
see what is docker. Docker provides the ability to package and run an application in a
loosely isolated environment called a container. The isolation and security allow you to run
many containers simultaneously on a given host. Containers are lightweight and contain everything
needed to run the application. So you don't need to rely on what is currently installed on
the host machine. We might be using different components for our application. Let's take an
example that we need mongodb database, radius for caching functionality, rabbitmq for messaging,
mysql database and so many other components. You might have noticed some compatibility issues
while using various components for our application. Some of the components may need some dependencies
of a particular version. But some other components may not support that particular version. Docker
is the best solution for this kind of issues. We can run each component in separate containers
with its own dependencies and libraries. All these containers can be placed in the same machine.
All that we need to do is to install docker in the host machine and containerize each component.
Containers are completely isolated environment. So docker is having two different editions,
community edition and enterprise edition. The community edition is the set of free
docker products and the enterprise edition is the certified and supported container platform.
Along with the enterprise edition we'll get some add-ons like image security, management etc. And of
course it is a paid platform. Now we are going with docker community edition. Docker is available for
all the major operating systems like windows, linux and mac. Let's see how we can install docker.
To install docker in your machine you can open docs.docker.com in a browser. Then you can
find an option, download and install which will navigate you to a get docker page. Here you
can choose the operating system of your machine. Inside windows option you can see a button, docker
desktop for windows which will download docker for windows. For linux, you can see the supported
platforms CentOS, Debian, Fedora, Ubuntu etc. If you are using a mac, there are two options, mac
with indel chip and mac with apple chip. You can choose the one based on your machine. Also you can
find some documentation explaining how to do the installation. Docker desktop is a graphical user
interface for docker. If you hover the mouse on the bottom docker icon, it will show the status of the
docker engine. Now you can see the docker engine is running. On the left side menu there is a menu
option named containers or apps which will list all the containers in your machine. From the images
menu option you can see the downloaded images in your machine. Volumes menu option will show you the
volumes configured. We'll be covering the docker volume in an upcoming video. Also you can access
the docker settings by clicking the settings button. There are some options in the settings
left side menu as well including software updates. First you have to understand the difference
between docker image and docker container. Docker images are read-only templates used to
build containers. Containers are the deployed instances created from those templates. So docker
images and docker containers are closely related. But for creating a docker container we must have
a docker image. Docker hub is a hosted repository service provided by docker for finding and sharing
docker images. You can access docker hub by opening hub.docker.com in a browser. First I'll show you
the repositories page. In this page you can create a new repository by clicking on the
create repository button. There are two types of repositories, public and private. Public
repositories can be accessed by anyone from this docker hub website. Private repositories can be
visible to you only. We can only create one private repository using a free plan. Now the explore page
will show us the available public repositories. These all are the public docker images. You can
see a lot of public images like ubuntu, alpine - alpine is a lightweight linux. Then redis, busy
box, python, node etc. You can freely use any public images from this docker hub. Now let me open httpd
which is the public image of apache web server. Here there are different tags which links to the
respective docker file. We'll discuss about docker file in a later stage. Here the first row tags
are for apache web server with version 2.4.53 and OS bullseye debian linux. The second row tags
represents same version but the OS is different. It uses alpine linux. Also there are a lot of
information in this documentation. You can scroll down to see the complete information. Now if I
click a tag, it will open the docker file in github. Here you can see the content of the docker file.
No need to worry about docker file now. We'll go in detail about docker files in a later stage.
Now I'll open the official image of alpine as well. Here you can see different tags for
different versions. The latest tag always be of the latest version. Now let's see
some of the basic docker commands. You can open command prompt or powershell in windows. If you
are using linux or mac, you can open the terminal. So as I told before, to create a docker container
we need a docker image. First let's see how we can download or pull docker images from the docker
hub. Then we'll create containers from those images. To pull or download a docker image you can
just provide docker pull, then the image name. Let's pull the apache web server image.
The image name is httpd. So let me provide 'docker pull httpd'. I have not mentioned
any tags in the pull request. So by default the docker will use latest tag while pulling the
image. You can see now the download got started. Now the download got completed. For
seeing the list of images in our machine, we can use docker image ls command. Now you can see
we have only one image in our machine. We can also use docker images command to list out images. That
will also work in the same way. Here you can see tag image id which is a unique id for the image
in our machine. Next let me show you how we can pull a docker image with a specific tag. So let's
pull apache web server with alpine OS. We can just use any of these tags. So just before pulling
the new image I'll delete the current image. For that I can use docker image rm, then the
image id of the docker image. You don't need to provide the entire image id. Just a few
characters in the beginning are sufficient. Now it got deleted. No images are listed in
docker images or docker image ls command. So let's pull the new image by providing
the tag along with the command. I am going to use alpine tag. We can provide the tag
after a colon along with the image name. Now it is getting downloaded. You can see the image in the list and the tag is
mentioned as alpine. We can also see the image list in our docker desktop application. Just click on
the images option in the left side menu and it will list out the available images. Here you can
see the image size and also we have the options to inspect, pull, push to hub and remove image. We
can inspect the image from command line using docker image inspect command. Also provide
the image id. In the response we can see a lot of details about this image. Next let's
create a container from this image and run it. For that we are going to use docker run command. So
in the documentation of the image you can see that this image is exposing a port 80. We can specify a
custom port number which will route to port 80 of the container. So let me provide docker run. I am
also providing a custom name for this container using hyphen hyphen name parameter. This is
optional. It is just to identify the container. Now we can provide a custom port number for port
80 using hyphen p parameter. I am providing 8 0 0 1. So I can access using 8 0 0 1 from
my machine. Docker will automatically route to port 80 of this container. Finally
providing the image id of the image. Now the docker container is created and it is
running. We can see the container in docker desktop by clicking on the container option in the left
side menu. Here you can see the status is showing as running and port number is also mentioned. Now
I can access the URL from my browser and it is showing a dummy page. But there is a problem as you
can see the container is running in the powershell and if i close the powershell window,
the container will get stopped. Now in the docker desktop you can see that the
status is showing as exited. I am also not able to access the page from the browser. It is
showing page can't be reached. Now let's create one more container from the same image. Please
note that we can create multiple containers from the same image. So I'm providing
docker run command again and providing a different name for the container. Let
the port number be 8 0 0 2. This time I am providing one more additional
parameter hyphen d. Hyphen d stands for detach. Now the container will start running in
the background. Finally providing the image id. Now it is only showing a value which is the
container id of the newly created container. Let's open docker desktop and you can see the new
container is running and listening for port number 8002. Let me try to browse the URL with 8002 port
number and it is working fine. We can see the list of docker containers using docker ps command. But
in the result you can only see one container. It is because docker ps command will only list
out the running containers. In order to see all the containers, means running and stopped
containers, we can use docker ps hyphen a command. Next I'll show you how we can delete a container.
We can delete the 'ApacheWebServer01' container. For that we can use docker rm,
then just provide the container id. Now docker ps hyphen a is listing only one
container. That means the other container got deleted. In docker desktop also you can
see that there is only one container now. Next I'll show you how we can stop a running
container. We can use docker stop command for that. You can see that the container is stopped.
I am unable to reach the page as well. We can use docker start
command to start a container. Now the page is reachable. So let me stop
this container and remove this container. There are no containers now. So let me delete
the image as well. We can also provide docker rmi command for deleting the image. It
works same as docker image rm command. Hope you are clear with these commands. We will be
seeing more about docker in the upcoming videos. So that's it for this video. Hope you liked it.
Please subscribe, like and share this video. See you all in the next video. Thank You!