Virtual Machines vs Docker Containers

09/04/2017
344
Embed

Watch the complete course at: https://diveintodocker.com

Hit the subscribe button to receive more videos like this!

Dive Into Docker is a complete course that's packed with examples and best practices. It was carefully crafted to take you from "What is Docker?" to happily Dockerizing your own applications with total confidence.

You are watching video #5 of the free preview.

---

Personal Website: https://nickjanetakis.com
Twitter: https://twitter.com/nickjanetakis
GitHub: https://github.com/nickjj

Transcript:

00:03

the first thing that you need to know is

00:05

docker containers are not virtual

00:08

machines back in 2014 when I was first

00:11

introduced to the concept of docker

00:13

containers I related them to being some

00:16

sort of lightweight or trimmed down

00:18

virtual machine the comparison made

00:21

sense because Dockers initial marketing

00:23

heavily leaned on it as something that

00:25

uses less memory and starts much faster

00:27

than virtual machines they kept throwing

00:30

around phrases like unlike a VM that

00:32

starts in minutes docker containers

00:35

start in about 50 milliseconds and

00:37

everywhere I looked there were

00:39

comparisons to VMs so once again docker

00:43

containers are not VMs now let's go

00:46

ahead and compare them side-by-side both

00:48

again by investigating what it looks

00:50

like to run in multiple applications on

00:53

a server using virtual machines one

00:56

layer at a time it all begins with some

00:58

type of infrastructure this could be

01:01

your laptop a dedicated server running

01:03

in a data center or a virtual private

01:06

server that you're using in the cloud

01:08

such as digital ocean or in Amazon ec2

01:12

instance on top of that server runs an

01:15

operating system on your laptop

01:17

this will likely be Mac OS Windows or

01:20

some distribution of Linux when we're

01:23

talking about VMs this is commonly

01:25

labeled as the host operating system

01:28

then we have a thing called the

01:30

hypervisor you can think of virtual

01:33

machines as a self-contained computer

01:35

packed into a single file but something

01:38

needs to be able to run that file that's

01:41

where a hypervisor comes into play and

01:43

there's two types of hypervisors first

01:46

our type 1 hypervisor x' that can

01:48

interface directly with your

01:50

infrastructures hardware the other is a

01:53

type 2 hypervisor which runs as an

01:56

application on top of your host

01:58

operating system we don't need to go too

02:01

deep into this but an example of type 1

02:03

hypervisor x' would be hyper kit on Mac

02:06

OS hyper-v on Windows and KVM on Linux

02:10

two popular type 2 hypervisors are

02:13

virtualbox and vmware usually type 1

02:16

hypervisor x' are more efficient because

02:19

they can bypass the host OS and interact

02:22

directly with the hardware of your

02:24

server but don't be thrown off by that

02:26

statement type 2 hypervisors are still

02:29

very efficient ok so the next layer in

02:32

this delicious server onion are your

02:35

guest operating systems let's say you

02:37

wanted to run 3 applications on your

02:40

server in total isolation that would

02:43

require spinning up 3 guest operating

02:45

systems which are all controlled by your

02:48

hypervisor they could all be the same

02:50

guest OS or different it doesn't matter

02:53

but the problem here is that each guest

02:56

OS in itself might be seven hundred

02:58

Meg's each that means you're using 2.1

03:01

gigs of disk space just for your guest

03:03

operating systems it gets worse too

03:06

because each guest OS needs its own CPU

03:09

and memory resources - there's a lot of

03:12

waste happening here then on top of that

03:14

each guest OS needs its own copy of

03:17

various binaries and libraries to lay

03:20

the groundwork down for whatever your

03:22

application needs to run for example you

03:25

might need lid PQ dev installed so that

03:28

your web applications library for

03:30

connecting to Postgres can connect to

03:32

your Postgres database if you're using

03:35

something like ruby then you would need

03:36

to install your gems

03:37

likewise with Python or no GS you would

03:41

install your packages just about every

03:43

major programming language has their own

03:45

package manager and you get the idea

03:47

since each application is different it's

03:49

expected that each app would have its

03:52

own set of library requirements finally

03:55

we have our application this is the

03:57

source code for whatever awesome

03:59

application you've built if you want

04:01

each app to be isolated you would need

04:03

to run each one inside of its own guest

04:06

OS so that's the story of running

04:09

virtual machines on a server now let's

04:12

compare that to docker containers docker

04:14

containers aren't adjectives we still

04:17

need some type of infrastructure to run

04:19

them like VMs this could be your laptop

04:22

or a server somewhere out there in the

04:24

cloud then we have our host operating

04:27

this could be anything you want that's

04:29

capable of running docker all major

04:32

distributions of Linux are supported and

04:34

there are ways to run docker on Mac OS

04:36

and Windows - ah finally something new

04:40

the docker Damon replaces the hypervisor

04:42

the docker Damon is a service that runs

04:45

in the background on your host OS and

04:47

manages everything required to run and

04:50

interact with docker containers we'll go

04:53

into much more detail on the dr. Damon

04:55

later on in this section next up we have

04:58

our binaries and libraries just like we

05:01

do on virtual machines but instead of

05:03

them being ran on a guest OS they get

05:06

built into special packages called

05:07

docker images then the doctor daemon

05:10

runs those images the last piece of the

05:13

puzzle is our applications each one

05:15

would end up residing in its own docker

05:17

image and will be managed independently

05:20

by the doctor Damon

05:21

typically each application and its

05:24

library dependencies get packed into the

05:26

same docker image as you can see each

05:28

application is still isolated and just

05:31

in case you didn't notice there's a lot

05:33

less moving parts with docker we don't

05:35

need to run any type of hypervisor or

05:37

virtual machine

05:39

instead the doctor daemon communicates

05:41

directly with the host operating system

05:43

and knows how to ration out resources

05:45

for the running docker containers it's

05:48

also an expert and ensuring each

05:50

container is isolated from both the host

05:52

OS and other containers the real-world

05:55

difference here means instead of having

05:57

to wait a minute for a virtual machine

05:59

to boot up you can start a docker

06:01

container in a few milliseconds you also

06:03

save a ton of disk space and other

06:06

system resources due to not needing to

06:08

lug around a bulky guest OS for each

06:11

application that you run there's also no

06:14

virtualization needed with docker since

06:16

it runs directly on the host OS what

06:18

that said don't let this lecture jade

06:21

your opinion of virtual machines both

06:23

VMs and docker have different use cases

06:25

in my opinion the virtual machines are

06:28

very good at isolating system resources

06:31

and entire working environments for

06:34

example if you owned a web hosting

06:36

company you would likely use virtual

06:38

machines to separate each customer

06:40

on the flipside Dockers philosophy is to

06:43

isolate individual applications not

06:46

entire systems a great example of this

06:49

would be breaking up a bunch of web apps

06:51

into their own Gawker images and we'll

06:54

go into more detail on the topic of when

06:56

you should use a VM verse stacker in

06:58

another lecture and don't worry if you

07:00

didn't fully understand this lecture

07:02

it's a very deep topic with a lot of

07:04

moving parts and technologies so let me

07:07

solidify everything with a brilliant

07:09

analogy that a once read from one of

07:11

Dockers guides you can think of virtual

07:14

machines as houses and you can think of

07:17

docker containers as apartment houses

07:20

are fully self-contained

07:21

and offer protection from unwanted

07:24

guests they also each have their own

07:26

infrastructure plumbing heating

07:29

electrical systems and so on in addition

07:32

to that most houses are going to have at

07:35

least a bedroom living area bathroom and

07:38

a kitchen if you only want a place to

07:41

sleep in poop it's going to be very hard

07:43

to find a house that meets those

07:44

requirements you'll very likely end up

07:47

buying more than you need because that's

07:49

how houses are built Apartments on the

07:51

other hand also offer protection from

07:54

unwanted guests but they are built

07:56

around a shared infrastructure each

07:58

apartment building offers shared

08:00

plumbing heating electrical systems and

08:03

so on to each apartment also apartments

08:06

can be bought in various sizes you can

08:09

buy a very small studio all the way to a

08:12

penthouse suite you are free to pick a

08:15

size that matches your exact needs so to

08:18

wrap things up docker containers share

08:21

resources with your host OS through the

08:23

doctor Damon whereas virtual machines do

08:26

not hopefully that clears things up for

08:28

you but now you might have a few other

08:30

questions such as how do I tell when I

08:33

should use a virtual machine or docker

08:35

containers or maybe you're even

08:37

wondering if docker containers are

08:39

compatible with virtual machines both

08:42

are very reasonable questions to ask and

08:44

I'll answer both of them in the next

08:46

lecture see you there

Categories:
Tags: