Docker Fundamentals | Introduction | Basic Commands

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
ladies and gentlemen today's topic is fundamentals of Dockers and is presented by one of my dear friend Satine and he is an expert in Dockers cube radix virtualization and much more Cheryl welcome to taxi tutorials hello students welcome to this class and in this class we are going to talk about what is darker because docker is a very very popular topic and subject this days my introduction my name is Satya I have 20 plus years of experience in the software engineering field most of my experience has been in large-scale distributed systems cloud and virtualization so first of all you know why this session dockers containers and kubernetes they are very very widely used technologies any large companies and small companies they use this technologies because this technologies it enables you to write highly scalable applications very quickly and very easily and again then the last but not least and the biggest reason because there are lots and lots of jobs which requires Dockers containers and kubernetes knowledge right if you just go and search in LinkedIn and in last 30 days there were 3,000 jobs posted in India with the key word Dockers and more than 15,000 in us right and this is also among this coronavirus care which is going on currently right so imagine if the if it's a regular normal time and if the market is doing good imaging the number of jobs right so that is one of the biggest reason for full stick programmers job interview in Italy people will ask you whether you know this or not and you are expected to know so that's why we are taking this session and again you know if you haven't used docker at all you don't put anything about docker this is the perfect class for you you don't need to have any background we are going to start from the very basic and we will take baby steps and things as we go along right and if you are expert doctor user this will serve as a refresher for you so let's dig into it so what are we going to cover in this series of classes we'll cover you know why really doctor is needed because even when doctor was not there ten or fifteen years back the software's were still being produced and the companies were still up fine and running building large-scale software so what was the need of talker and wise doctor we are also going to look into what exactly is doctor what are the different components of talker and we will also see along with talker you always hear the word container right so we'll understand what exactly is a container and then we will also see behind the scene what exactly is happening what are the technologies and what are the concepts which make Dockers and containers possible we will look at some basic docker commands and we will also look at you know how to create a docker image so overall in this class it's going to be a fun interactive and hands-on class right so we are not just going to talk about theory but we will do practicals as we go along now let's see first of all why is docking needed so let's look at a typical flow to install any software right so you download an installer you run the installer and when you run the installer there could be two outcomes either you will run into an error or the installation will be successful right now if it's a complex software then more often than not you will run into an error right you resolve the error after you resolve the error you might run into a another error again you resolve the error and you keep repeating that cycle until your installation is successful right and once installation is successful you may have to go and do proper configuration modify some configuration files and restart your software and then eventually it is your application is ready to run and you are ready to use your application it's a very involved process right in software installation normally it happens only one time so it is taking your productive time away right and as an application programmer and developer why do you really need to spend so much time in installing and configuring your software right so let's see how this happens with a live example I'm going to install a radius server on my local machine and for those who don't know radius is a highly scalable in-memory database that many web applications they use it today right so let's go to the release page download page and it lists out some simple steps for installation let's try to run the first command if I run that first command let's see what happens and there you get it says that the command not found W get command not found because on my local machine I do not have the W get program installed that's why I ran into this error to install radius W get is one of my dependencies right and I have to first go and download this W yet right so if as you see that you know that installation is not just single step and it's it's not that easy let's see how docker can help in this and to use docker first we will have to go ahead and install the docker on our local machine right so for that first you have to sign up a docker right so let's go there I have already signed up for the account but what you need to do is that you need to go ahead and sign up it will ask you for your foreign or ID which is nothing but user ID and then your email and password right once you sign up what you do is you go back to dr. calm and you go to get started and we need to install the desktop version of the docker since I'm using Mac I'm going to download it for Mac dr. dot dmg file I have already pre downloaded and printed all docker on my machine but you can go ahead and download that dmg file if you are running Mac if you are running Windows there is you know steps that you can follow which once you go to that window space over here it will list out the steps but go ahead and install and once you install on your desktop machine what actually it is doing is it is going to install docker client and server on your machine and as you see here where my mouse pointer is there is this icon here right which looks like a well and with some containers on top of it so that's you should be able to see that symbol after the installation right let's see so for me you know that docker desktop is already running let me just try to restart and see what happens right so when I restart and when you try to install you will also see something like this this containers they are little containers they are dancing and you will see dr. desktop is starting in few seconds you will see that you know it is installed and up and running and you will see it green okay just give it a few seconds okay so now you see docker desktop is running and once it is running if you type this command it will tell you that what it is installed and what is running right so when I do the darker version it tells me that docker client is running what is the version and you know blah blah blah some other stuff the same way it will give you detail about the docker server right so the docker installation it installs docker client and somewhere on your machine let us try to install the same ready server or using docker and let's see what happens docker run Redis and if I do this let's see what happens so over here what it did really it it said that you know it is ready to accept connections basically you're ready server is up and running and ready to use in few seconds or a few minutes right in this case it was very quick just because I had a docker image already installed on my machine so let me show you once more let me remove that image that is right okay so now that image was gone I'm also going to remove another image that I'll be using later on for the class okay now let me run that command docker run reddy's right so it is going to take couple of minutes what it is doing is actually it is going to the docker hub it is downloading the radius image and then it will install and start already server right so it says ready to accept still it took around a minute right so as you see you know with docker you are basically ready to run your server in about a minute right so that is the fundamental problem that docker solves right it makes the installation very very easy you don't have to worry about dependencies and configuration right isn't that cool right as the application developer why should you worry about really installation right of your software you should be you should spend more time in really writing the application rather than figuring out the installation part so that's the fundamental problem that darker solves the next question is what exactly is daughter right you might hear your colleagues you might see on a job posting that docker is required now actually what they mean by docker is the docker ecosystem and docker ecosystem has different components dr. Klein docker server which is what we downloaded on our machine then there is docker hub then there are docker images there is something called docker compose docker machine each of these components they have different purpose and we'll talk about some of this today now let's run you know another example hello world right like in any other programming language or anything that you learn new it's a very popular thing hello world right so doctor also has this hello world and try to understand exactly you know what is happening behind the scene so I'm going to stop this ready server and then let's run this image or let's run this come on I'm sorry doc around hello world right so what it did that image doesn't do much other than it says that hello from docker and it gives some other messages and we'll see it in a second right so let us see what actually happens right so docker run hello world when I type that command that command was basically intercepted by the it's the docker client right when I run the command docker on hello world so the command went to the doctor client and docker client it it doesn't have lot of logic in build all it does is it passes on the command passes the command and then passes it sends the command to the docker server right now docker server what it does is it looks at the cache image cache in the local computer and what this image cache is that it is basically let's say if you have downloaded some docker image before then it gets stored in the local image cache right so it it's it looks for hello world image whether it is already there or not it looks for it it's it sees that it is not there so it contacts the docker hub right and docker hub certainly has this hello world image so it downloads the hello world image put it in the local cache and then it runs right so that's what really happened let's look at our turbulent the messages right see when I type in docker on hello world initially it said that unable to find the image hello world locally right then it says that it is pulling the image then it downloaded the image and then it brings the message alright so if you see this message it really tries to explain you exactly what are the steps that docker to dr. client contacted the docker daemon and dr. diamond is nothing but docker server docker daemon pulled the hello world image from the docker hub and dr. daemon created a new container after it downloaded the image it needs to create a container right out of that image so that's what it did and then after that it really rained that container and the output from that you know container it was sent to your terminal so that's what happened and that terminal is this what we are looking at currently right this output ok so that's what that's a basic example and we talked about exactly you know when you run any darker command to run a container what is happening look at what exactly is happening behind the same right because I mean to make things simple so simple right installation with a single command there is a lot of things happening behind the scene right and to understand that let's look some high-level concepts right so in your typical machine or your computer you have some hardware and that hardware is your hard drive your network card your network interfaces your CPU which is really the brain of your computer and it provides the processing power and then also the memory right and then on the top you have some applications running right you might have database applications you have web browser you have your own applications they are running on your computer and all these applications they need some hardware resources from your machine right they need network they need hard drive space they need processing power from CPU they need memory to you know put things into memory cache so that the application runs very fast right so what is it that controls and governs all those excess so there is something called kernel right so kernel it sits in between all your applications and all this hard drive or hardware resources on your machine right which governs or which controls the XS - all these applications right and coordinates also okay so there are two concepts which makes the docker technology docker and container technology possible right one is something called namespace right so namespace is nothing but it isolates the resources per process and second one is the C group which limits the amount of resources that each process can use right so let let's look at what it is right so for example let's say previa in the previous slide we saw this MongoDB and browser and kernel another part right let's say if I put you know MongoDB in a separate namespace and the browser in a separate namespace then what you know kernel does by using the namespaces that it creates a separate whole execution space isolated space for MongoDB and MongoDB it sees it sees that you know there is some specific hardware resources it is allocated for it right and also how much it can use right so all those that is controlled by the control groups and the same for browser also it is allocated a different space right for its own so what that means is for example let's say if MongoDB is writing to some file right and creating that file in the hard drive the browser will not be able to see that hard drive even though they are running on the same machine right if you are using namespace separate namespace one for MongoDB and one for browser the browser will not be able to see any file return by MongoDB browser on the hard drive so for example let's say if we are not using namespace right then and then MongoDB is creating creating a hard creating a file on a hard drive and if it has a proper read write and execute permission for any other process then even browser or any other application will be able to see that file or read from that file but with namespace they cannot do it directly right there are other mechanisms how to do they do it and how to share but normally they cannot do it and this is the two concepts namespace and control groups which makes container technology possible right so you can so in container also you can just imagine that this is one container right it has it has its own resources and this is another container which has its own hardware resources so this if you see the previous slide I mentioned that it is supported on the linux right now it is supported on the linux then how you know docker is possible on Mac and Windows right because some of these concepts are not supported by Mac and Windows so I surely when I downloaded docker right so it downloaded something called virtual machine as well Linux virtual machine so the Linux virtual machine is sits on top of the kernel right and it provides all this you know namespace and control groups concepts and all your application then any application which runs inside this virtual machine it can take advantage of the docker technology so let's see when you know when I let me show you if i type the docker version right even though I'm running my using Mac if you see if I type docker version it says that the OS well let's look at the server part right so it says that I'm running Linux right it is it did not show me that I am running Mac it shows that I am running Linux right that piece so really docker server is basically running inside a virtual machine I hope you know this is making things clear for you guys so let's see what is an image and what is a container right so image is nothing but snapshot of a filesystem with some startup command in it right so let let us understand what what exactly it is right so when we had when I had the tradies image so in the radius image what it had is it had some radius it has radius plus some other dependent libraries and it had some initial start of command that's what that image contained right and what I can do with that image I can when I run that image right it creates a container and it starts the container using this start of command right and it tries to put that image into basically cache or memory of your machine right so busy so that container he is consider that you have an executable on a program on Windows right and when you want to run it that executable or binary when you run it it becomes a process right so whatever is the relation between executable or binary and the process the relationship between image and container is same you can create multiple container from the same image let me show you one example with on that so that is some other image called busy box right busy box and I'm going to do ping google.com so it will do nothing not much but yeah so it is unable to file find the email locally it download the image and then it is running this command now if I go to this other terminal I can run the same command docker run busy box ping google.com and when I do this say you see I have I use the same image but I have two different containers using the same image and if I want to see that how let me show you how I'm going to create a new tab and if I docker PS say it shows me that I have two containers running using the same image these are the container ID for and they both are using the same image busybox right and you can see that they were started just a few seconds ago right so now let me stop one of them and then see run this command again right now you see only one of them and if I even stop this you will not see anything container with an image you can run multiple containers so now we saw you know what is happening behind the scene and what are the concepts that make container technology container and opera technology possible right let's look at some simple operations or basic commands for the containers so first we will see list containers right so right now I don't have you know anything running so you will not see anything now let me start that one of the busybox container again again and if I run it now say it will show me this it will show me whatever is the running containers are if I do this right what it will show it will show me all the containers not only the containers which are running currently but all the containers that I ran right it will show me the history so for example if you see the first container over here it shows me that it is the status of 30 seconds ago and it is still running right and then you know you will see this name so it tries to give the name to the container right and this names are randomly generated and it it will show the container ID also so with the container ID we'll talk about it container ID is very similar to process ID and you can use it to run other commands right and if you see the other containers or other containers in this list it says that say this was the busy box that we ran couple of minutes ago and you can see that it was exited if I do this part let's say the other thing that I wanted to show you was so we saw this command now running a container right so let me show you again we saw few times that when I run this container it is just running right but behind the scene what actually it is doing is that the run command it has two components to it two parts of it so one it creates container out of the image so when I run this command docker run busybox ping google.com it takes this busybox image it creates a container out of it and then it also starts the container with some startup command right and when I you know pass a command like this ping google.com that is a I'm overriding the start of command which is already there in the busy box image instead of running creating and running a container in a single step I can do it in in to step all so for example there is this thing let me show you I can let's stop this busy box image and what we can do is let's use the Redis right so I can say that docker create radius so it already had a radius image so it did not have to download but what it did it created this long it created the container out of it and then it created this long container ID right let's see if the container is running or not right so container is not running now what I can do is that I can use the start command to start this container and add I will have to pass the container ID so I don't have to pass the complete I will have to pass no initial few digits that can identify it uniquely right so once I started okay let's see what happened I should be able to see docker yes see 3ds container it basically started 52 seconds ago right what I can do is that now I can stop this container so look at the status here it is showing me up and it is running right what I can do is that I can stop right and again if I do PS it went away right and if I want to see again the same container if I do PS - a look at this what was the affectionate boss right it said that exited eight seconds ago and I can restart again right so for example I can start it again right and let's see doc es - rather than es - eh I'm going to do just PS so you can see only that container it's now let's say if I want to permanently kill this container how do I do it so to permanently kill the container I use the docker kill command and then right let me see now do I do know right now let me start the let me try to start this container right let's see did it really work did it start yeah it did start right so you can do that now yeah so if I kill it again docker PS yes and then you know docker PS - eh if I do this it will show me everything that it exited and other part right now the one thing that I wanted to show you was that you know why even though all these containers I had already stopped it why are they still showing up because what happens is that docker it maintains a table where you know it shows that what it meant is the history of all the containers with the status and everything right how do I do that so what I can do is that I can clear that up by running this command docker system prune [Music] they will ask you that so what it will say is that it will remove all the stop containers all networks not used by at least one container or dangling images all dangling build cache and everything right so all the resources that you know being used by stop containers it will release it in case if they are still not cleaned up okay it will not impact the running container store okay so look at this now if I run the docker PS command it doesn't show anything right so that's there now let's say the other part I wanted to show you was that for example if I run the hello world image right it is say the hello world image is it was there so I did not have to go in download now let's say either you are running out of space or you decide that you know you don't need to have this image anymore right so in that case you just want to get rid of completely you know delete this image so for that what you need to do is that you have to use this command no naka RM I remove image and say hello world right okay so here it is giving me a response error response right because it says that conflict are able to remove equals eteri reference hello world must force right and you know the reason why let's see where is the reference because if I run this command see you will see this hello world in that table still right so first I have to remove that reference from the table I have to run this command so one side on this it is removed from that table right and after that if I don the image sometimes it takes a little bit of time to clean up that table where it maintains all the stop can Tanner's info about all the stop containers that okay this time it was successful right so we removed the image and now again if we run they run the command hello world see it did not find the image locally and it had to download that means with the remove command the image was really gone from even our cache and everywhere if you want to go and get access to the shell right inside a container how do you do that release command docker run readies let me get the dock yes I got my ID for the Redis and then what I do is that docker exact I T YT then my ID I need the Redis part dock exact I T paste and SH right if I do this so now I am inside really the radius container right I can run okay I can run different commands right that let's see if there is anything here yes look it shows me what is inside that docker container right the Redis container it has been data and all this different directories right so this is how I can get in inside a container if I type exit I get out of that alright folks so in the next video of this series we will look at creating your own image using Dockers and then we will look at a small project using nodejs and we will try to understand docker compose and multiple containers and that will be the next video and I hope you learned something from this video and if you did please like subscribe and provide a nice comment and I'll provide a link to the next video here thank you [Music]
Info
Channel: techsith
Views: 7,519
Rating: 4.9295774 out of 5
Keywords:
Id: s7h14GGdjQc
Channel Id: undefined
Length: 36min 4sec (2164 seconds)
Published: Wed Apr 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.