Virtual Machines vs Docker Containers - Dive Into Docker

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the first thing that you need to know is docker containers are not virtual machines back in 2014 when I was first introduced to the concept of docker containers I related them to being some sort of lightweight or trimmed down virtual machine the comparison made sense because Dockers initial marketing heavily leaned on it as something that uses less memory and starts much faster than virtual machines they kept throwing around phrases like unlike a VM that starts in minutes docker containers start in about 50 milliseconds and everywhere I looked there were comparisons to VMs so once again docker containers are not VMs now let's go ahead and compare them side-by-side both again by investigating what it looks like to run in multiple applications on a server using virtual machines one layer at a time it all begins with some type of infrastructure this could be your laptop a dedicated server running in a data center or a virtual private server that you're using in the cloud such as digital ocean or in Amazon ec2 instance on top of that server runs an operating system on your laptop this will likely be Mac OS Windows or some distribution of Linux when we're talking about VMs this is commonly labeled as the host operating system then we have a thing called the hypervisor you can think of virtual machines as a self-contained computer packed into a single file but something needs to be able to run that file that's where a hypervisor comes into play and there's two types of hypervisors first our type 1 hypervisor x' that can interface directly with your infrastructures hardware the other is a type 2 hypervisor which runs as an application on top of your host operating system we don't need to go too deep into this but an example of type 1 hypervisor x' would be hyper kit on Mac OS hyper-v on Windows and KVM on Linux two popular type 2 hypervisors are virtualbox and vmware usually type 1 hypervisor x' are more efficient because they can bypass the host OS and interact directly with the hardware of your server but don't be thrown off by that statement type 2 hypervisors are still very efficient ok so the next layer in this delicious server onion are your guest operating systems let's say you wanted to run 3 applications on your server in total isolation that would require spinning up 3 guest operating systems which are all controlled by your hypervisor they could all be the same guest OS or different it doesn't matter but the problem here is that each guest OS in itself might be seven hundred Meg's each that means you're using 2.1 gigs of disk space just for your guest operating systems it gets worse too because each guest OS needs its own CPU and memory resources - there's a lot of waste happening here then on top of that each guest OS needs its own copy of various binaries and libraries to lay the groundwork down for whatever your application needs to run for example you might need lid PQ dev installed so that your web applications library for connecting to Postgres can connect to your Postgres database if you're using something like ruby then you would need to install your gems likewise with Python or no GS you would install your packages just about every major programming language has their own package manager and you get the idea since each application is different it's expected that each app would have its own set of library requirements finally we have our application this is the source code for whatever awesome application you've built if you want each app to be isolated you would need to run each one inside of its own guest OS so that's the story of running virtual machines on a server now let's compare that to docker containers docker containers aren't adjectives we still need some type of infrastructure to run them like VMs this could be your laptop or a server somewhere out there in the cloud then we have our host operating this could be anything you want that's capable of running docker all major distributions of Linux are supported and there are ways to run docker on Mac OS and Windows - ah finally something new the docker Damon replaces the hypervisor the docker Damon is a service that runs in the background on your host OS and manages everything required to run and interact with docker containers we'll go into much more detail on the dr. Damon later on in this section next up we have our binaries and libraries just like we do on virtual machines but instead of them being ran on a guest OS they get built into special packages called docker images then the doctor daemon runs those images the last piece of the puzzle is our applications each one would end up residing in its own docker image and will be managed independently by the doctor Damon typically each application and its library dependencies get packed into the same docker image as you can see each application is still isolated and just in case you didn't notice there's a lot less moving parts with docker we don't need to run any type of hypervisor or virtual machine instead the doctor daemon communicates directly with the host operating system and knows how to ration out resources for the running docker containers it's also an expert and ensuring each container is isolated from both the host OS and other containers the real-world difference here means instead of having to wait a minute for a virtual machine to boot up you can start a docker container in a few milliseconds you also save a ton of disk space and other system resources due to not needing to lug around a bulky guest OS for each application that you run there's also no virtualization needed with docker since it runs directly on the host OS what that said don't let this lecture jade your opinion of virtual machines both VMs and docker have different use cases in my opinion the virtual machines are very good at isolating system resources and entire working environments for example if you owned a web hosting company you would likely use virtual machines to separate each customer on the flipside Dockers philosophy is to isolate individual applications not entire systems a great example of this would be breaking up a bunch of web apps into their own Gawker images and we'll go into more detail on the topic of when you should use a VM verse stacker in another lecture and don't worry if you didn't fully understand this lecture it's a very deep topic with a lot of moving parts and technologies so let me solidify everything with a brilliant analogy that a once read from one of Dockers guides you can think of virtual machines as houses and you can think of docker containers as apartment houses are fully self-contained and offer protection from unwanted guests they also each have their own infrastructure plumbing heating electrical systems and so on in addition to that most houses are going to have at least a bedroom living area bathroom and a kitchen if you only want a place to sleep in poop it's going to be very hard to find a house that meets those requirements you'll very likely end up buying more than you need because that's how houses are built Apartments on the other hand also offer protection from unwanted guests but they are built around a shared infrastructure each apartment building offers shared plumbing heating electrical systems and so on to each apartment also apartments can be bought in various sizes you can buy a very small studio all the way to a penthouse suite you are free to pick a size that matches your exact needs so to wrap things up docker containers share resources with your host OS through the doctor Damon whereas virtual machines do not hopefully that clears things up for you but now you might have a few other questions such as how do I tell when I should use a virtual machine or docker containers or maybe you're even wondering if docker containers are compatible with virtual machines both are very reasonable questions to ask and I'll answer both of them in the next lecture see you there
Info
Channel: Nick Janetakis
Views: 251,400
Rating: 4.949223 out of 5
Keywords: Docker, Docker Tutorial, Docker Course, Docker Example
Id: TvnZTi_gaNc
Channel Id: undefined
Length: 8min 48sec (528 seconds)
Published: Sun Jul 02 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.