what exactly is virtual machine see honestly speaking in this world today when we are working with cloud computing virtualization is not something new we have been very frequently creating virtual machines and on top of these virtual machines we have been installing the required softwares which can be our web-based applications which can be console based applications which can be services various types of applications May install we use them as and when needed persist data and so on but actually how is virtualization created see in the past we talk about let us say absolute basic computer which has all the required hardware Let It Be Your processor memory storage network card mouse keyboard CPU whatever entire Hardware which is completely managed by an operating system the operating system can be Linux the operating system can be Windows the operating system can be Mac the operating system is supposed to have a list of drivers we call them as device drivers yeah the generation today is very lucky you don't really bother a lot about device drivers most of them are like Plug and Play you connect a computer with the printer and you start using the printer rarely you need to actually install an additional driver but those days when I started my career at least some sometime in 1992 95 93 94 the operating system was dos it was really a challenge to install the device driver and make the device work on the computer of course with the Advent of Windows 95 that was in the year 1995 things became little easy the device drivers became plug and play and then we were able to Simply attach a device and install the driver with few clicks here and there and make it work and then things only became easy day by day and today you most of the people don't even know that the operating system layer in background uses a device driver which is responsible for converting the high level instructions of the operating system into the lower level instructions understood by the hardware and of course vice versa reverse also and on top of the operating system lies our application these applications are one what we have developed as in dotnet developer you might have built some application as a Java developer you might have built some application or maybe C and C plus plus if you are a legacy developer or python application some kind of applications which you might have developed on top of an operating system so how does this whole system work the application which we developed let us say I used C programming language to do something I will write my code and I will invoke the API of the operating system application programming interface of the operating system that means my application makes call to the OS libraries and this OS libraries facilitate converting our instructions into the hardware understandable format with the help of device drivers and at the same time they take our instructions into the processor data on the disk and like this the entire system is working so the applications which we built are always specific to the operating system like CNC plus plus application specifically because the CLC plus plus instructions are tightly coupled in machine code format with the operating system java.net now python PHP these are not OS specific instructions what they do is on top of operating system they build one more layer which they call it as a runtime layer if it is Windows this will be Java runtime for Windows if this operating system is Linux it will be Java runtime for Linux if this is Mac this will be Java runtime for Mac and this runtime which is very specific to the operating system will then be responsible for converting the instructions which we compile let's say from javasource code to Java byte code and the bytecode instructions will be compiled by Java runtime into OS specific and Os Specific Instructions will further go down to the hardware and execute so these languages Java now.net core python PHP all this we put it under the category of platform independent programming languages for the reason that they are not tightly coupled with the operating system the compiled output of java called as byte code the compiled output of dot net we would call it as msil code or IL code now likewise we do have Pi code python compiled output all these things require the respective runtime and the respective runtime which is tightly coupled with the operating system will take care of converting from one format to the other format and execute blah blah blah blah blah story not really interested in that point is if I use let's say dotnet for development of my application I might do development in dotnet core 3.2 so init.net core 3.2 on every machine where I should execute my application or if I develop today let us say in.net 7 I will need dotnet runtime 7 on every machine where I would like to execute my application that means our application which we have built is pretty much dependent on the runtime which is required for execution of that application and that too the compatible version is needed fantastic likewise same is the case with Java you might use Java jvm and there are different versions of jvm python also has got version 2 version 3 a lot of things which are built on python 2 are not compatible with Python 3 because it was a revolution which came point is simple every application has certain dependencies and those dependencies are needed as it is without those dependencies our applications are not going to work so how do we handle this situation what if my machine requires python 2 also python3 also dot net core 3.2 also dot net code 6 also.net 7 also I want to run all the applications there will be definitely chaos there will be definitely lot of incompatibilities which can lead to situation where some application was working already on this particular machine I installed another application and that application needed the latest libraries so on installation of latest libraries imagine the old version libraries got upgraded and the new application now starts working the old application will stop working this can be a typical situation where we ended up upgrading our applications new version but some of the old versions will stop working radical problem to see which lot of people face in the industry how can this be resolved simple I let's say take a virtual machine what is a virtual machine now I would say a virtual machine is nothing but a software machine a hardware being treated like a software and with the software will create a virtual machine so ultimately we will have all the hardware here Let It Be CPU Ram processor all that Hardware will be there on top of that Hardware we are going to implement virtualization we are going to use something like virtual machine monitor bmm which can be hyper-v which can be virtual box which can be VMware there are lot of virtual machine monitors so these in generalizes generalized term I could call it as hypervisor these hypervisors are what I am going to use for building these virtual machines every virtual machine will reserve some Hardware from The Host is your base physical hardware and then there is a virtual Hardware which every virtual machine will have access to so let us say I've got 64 DB RAM on my physical Hardware I will create one virtual machine with 16 GB I may create another virtual machine with another 16 GB and these 16 GBS are reserved for the respective virtual machines and the applications which are going to be installed in one virtual machine will also see that it has got its it has got its own guest operating system so let us assume that we are working with something like this we are working with the hardware on top of which some hypervisor is installed and on top of this hypervisor direct virtual machines are created these type of virtual machines are type 1 virtual machines the alternative solution is we have the hardware managed by some host operating system which can be Windows Server which can be Linux server and on top of that host operating system we will have hypervisor and that is when we can manage the virtual machine the difference is here we do not have the host operating system here we have the host operating system but in either case we are going to have a hypervisor type one hypervisor type 2 hypervisor and on top of these virtual machines are created beauty is what every virtual machine can have its own applications every virtual machine can have its own dependencies and every virtual machine also will have its own operating system so here I might have a host operating system which is let us say windows and on top of it I'll create a virtual machine in Linux or I'll create a virtual machine using Windows in a Linux based virtual machine I will install all Linux based applications and on a Windows based virtual machine I will install all windows based applications that means on one physical Hardware we are able to have different operating system environments yes every virtual machine is isolated from the other virtual machine every machine is isolated from the other there is no overlapping at all windows will have its own network and IP address Linux machine Also may be part of the same network but will have its own IP address and because the guest operating system is absolutely different every virtual machine will have its own pile system suppose this application in this virtual machine uses the file system that belongs to this guest operating system and the other virtual machine will again have its own guest operating system and its own file system the files of one VM do not in any way overlap with files of another VM they're absolutely independent of each other that's the beauty so like this when virtual machines are independent there is no overlapping applications with different versions different runtimes can independently work with within each VM and there is absolutely no problem good very similar concept of this is what is virtualization here also we are going to have an host operating system on top of the host operating system we will create a Docker engine and on top of Docker engine you'll have some dependencies ignore this for a while and then we are going to create containers like virtual machines are created from VM images for every virtual machine we need something called as VM image something very similar is what is needed for containers also for me to create a container we need a container image so if I write in simple Layman's language I have a VM image and from the VM image I am going to create a VM instance like that we can say today we have got container image from which I am going to create a container instance generally people refer container image as simple image and container instance as simple containers that's it that's a short short form container instance is a container and the container image is a container is referred as image so we need an image now this image I'm saying is very similar to the image of virtual machine what is that virtual machine image will have every virtual machine image is supposed to have the base operating system which can be Linux or which can be Unix sorry which can be windows or any flavor of Linux and on top of it you might probably install certain software and then you create an image out of it so when I create a VM instance all that software which we installed in the image is going to be part of the VM instance say for example I create a base machine with Windows 2022 server and on top of it I install SQL Server and then I create a image out of it from that image if I create a virtual machine I will have SQL Server software ready in that virtual machine likewise here also we are going to have a base image on top of which we are going to install our application our software and then create an image out of it Custom Image we call it and then from the Custom Image we can create container one image can have multiple container instances if needed in a Layman's language if I explain I can have notepad.exe this notepad.exe I can create a instance and that becomes a notepad instance this
is one notepad instance notepad.exe was launched and that became one notepad instant I can create one more instance of notepad.exe this is one more instance so these are windows based application for which we are creating multiple instances like that in Docker World in containerization world we are going to find a image from which we are going to create multiple container instances yes that is what is the containerization all about but the question is when virtualization is already there what is the benefit which containerization is going to provide when we create a container every container is again isolated from another container every container is going to have its own file system the applications running in the container if they create some files or write something into those files or if they use certain files these are isolated from the entire file system which would be created for another container absolutely independent no overlapping at all so when container file systems are independent can I have the same benefit what I got with virtual machine I can have one version of my application let's say dotnet application which I developed in.net
3.0 or 3.2 I will put in that container all the runtime up files which are required by dotnet 3.2 application and when I have dot Net 7 application the dot Net 7 runtime will be separately packaged into a separate image .net runtime 3.2 1 image dotnet runtime 7.0 another image no overlapping at all respective images would be used for building the respective images with our custom application if I explain in little more detail I would take the base image for let's say dotnet 3.2 on top top of it add my custom application and what I'll get is a new image this I'm saying is base image of dot net 3.0 custom application what is customer application the files related to the application which I have developed the binaries of my application which I have developed and that becomes a new Custom Image which has my application and from this image I am going to create a container like that there can be a base image of dotnet 7.0 Plus in it I'll put the application which I have developed in dotnet 7.0
and I'm going to create a new Custom Image of course that will have a different name and from that I'll create a separate container is there any overlapping no treat every container as a process by itself the container runs absolutely independent of this container this container will have its own file system which is constructed from this and this this container will have its own file system which is constructed from here which is based on this and this and they are absolutely independent they don't see internal view of each other so because of containerization we are able to run the application with ease as it has not only the primary application files but also all the dependencies which are required for my application to run actually speaking this base image of dotnet 2 how was it built That Base image of dotnet 2 probably was built with the base operating system and all the runtime software required for dotnet 3.2 likewise here also we might have the base operating system and then the runtime software of 7.0 so layer by layer images are actually built I'll talk little more about it later but point to understand is containers are isolated from each other containers will have file system as defined by the image from which the container is created from same image we can have multiple container instances created even then they are isolated from each other a container will have its own IP address every container will form a network with other containers on the same machine so basically am I not talking the same language what I would do it for the virtual machine absolutely yes whatever I'm saying for the virtual machine same thing I'm putting it for the containers all then what is the difference huge difference if you look at the diagram itself a container does not have an operating system of its own a container will only have an application and its dependencies but it doesn't have the OS patch not because what could be the question how will the application run without the operating system yes the containers are built in such a way that for all their operating system requirements they are going to use the host operating system kernel the kernel where actual instructions are executed will be sent to the host operating system that's why I said earlier you should treat every container just as a separate process and because they are using the host operating system kernel can I say they are very lightweight as they don't have to load the operating system and the libraries which are used for running the application unlike as in VM VM is heavy imagine if I have 16 GB 16 GB reserved for two virtual machines out of 64 GB 32 is gone and I'm left with only 32 for the host operating system applications and I can't use that extra memory I mean that memory even if it is unused by the applications which are running in that PM because that is the reserved VMP will block it unlike that the container will give us the facility of using what is needed and of course also giving us the ability to restrict to a particular limit if in case needed I would say yes maximum 16 GB but container might use only 10 GB container one might use only 8 GB the remaining can be used by other contents container will not block that amount of memory which I have capped for a particular content cap can be provided but there is no lower limit so yes very very important containers are lightweight containers are as good as virtual machine but they don't have operating system patch that's why they save lots and lots of memory if I have three virtual machines three times the same patch would repeat three times the memory is invested for every virtual machine separate patch oh that's expensive that wouldn't happen in case of container the same host operating system kernel will be used though the files will be different but this leads to one limitation and you should clearly remember this I can have host operating system Windows and create a Linux virtual machine and this application then can be Linux based I can have host operating system Linux create a Windows Virtual Machine and then this application can be Windows because it has the corresponding guest operating system taking care of all the low level instructions and through hypervisor they're going to the hardware and executing it in containerization it's not like that if the host is Windows you can only create containers which were built for Windows from images which were built for Windows if the container is if the host is Linux you can only create these containers which are which are Linux based the images when they are created they have to be Windows based or they have to be Linux based very clearly I'm repeating images when they are created at that point of time we have to be very clear is the image for Windows or is the image for Linux if windows image will not work on Linux and Linux image will not work on Windows they are very much Native this is one of the confusion which is probably there for a lot of people that containers are platform independent no containers are always specific to the platform for which they are built is definitely not a replacement for virtualization but very similar to virtualization virtual machines are unique isolated containers are unique isolated virtual machines will have their own file system containers will have their own file system the directory structure of one container will not be visible to another container so is the case with virtual machine virtual machines will have unique Network identity same thing with container they form Network applications from one virtual machine can communicate with application in another virtual machine so is the case with containers the application in one container can communicate with application in another container application to application communication can happen I can have my web application bundled in one container and my database application bundled in another container I can do that and the web application by way of connection string which includes the IP address of the other container can talk to the database container though they are very similar containers do not replace virtual machine in most of the situation it may happen today especially in the world of virtualization when we move to cloud like Azure or AWS or gcp we actually create virtual machines and inside those virtual machines will create containers the host can be virtual machine but in addition to that host there can be containers created that's the beauty we can actually enjoy today yes containers are the future way of developing and distributing applications so that the life becomes easy as we don't have to take care of the dependencies as they are all bundled together in a common image so that's why I say container is nothing but virtual machine minus guest operating system
2023-05-31