1 00:00:00,000 --> 00:00:04,564 [MUSIC] 2 00:00:04,564 --> 00:00:09,240 In the last stage we took a look at what Docker is and why people use it. 3 00:00:09,240 --> 00:00:13,260 In this stage we'll look at how Docker can streamline your software development in 4 00:00:13,260 --> 00:00:14,060 a bid way. 5 00:00:15,090 --> 00:00:19,820 Long ago, developers had to install all of their apps dependencies on the OS itself 6 00:00:19,820 --> 00:00:22,560 before they could even begin development work. 7 00:00:22,560 --> 00:00:26,480 This may work for your purposes, but when it comes time to let a team mate or 8 00:00:26,480 --> 00:00:29,770 customer use your code, there can be many problems. 9 00:00:29,770 --> 00:00:34,550 It's not always easy to reproduce what worked on your machine on their machine. 10 00:00:34,550 --> 00:00:36,979 Then came virtual machines which really save the day. 11 00:00:36,979 --> 00:00:41,947 VMs essentially emulated entire computers with in a developer's computer, 12 00:00:41,947 --> 00:00:46,312 VMs were great because they allow developers to install their app's 13 00:00:46,312 --> 00:00:51,300 dependencies in a virtual machine keeping it isolated from main OS. 14 00:00:51,300 --> 00:00:52,970 In certain configurations and for 15 00:00:52,970 --> 00:00:57,500 certain apps, they can even be faster than running on native hardware. 16 00:00:57,500 --> 00:00:59,870 But this isn't the case most of the time. 17 00:00:59,870 --> 00:01:02,980 Because a virtual machine has to emulate all the hardware and 18 00:01:02,980 --> 00:01:06,250 firmware it runs on, it can be slow to start up. 19 00:01:06,250 --> 00:01:08,631 And VMs are slower to run in most circumstances. 20 00:01:08,631 --> 00:01:13,385 And because the images contain an entire operating system including packages 21 00:01:13,385 --> 00:01:18,007 an app may not need, the disk images are big and impractical to distribute. 22 00:01:18,007 --> 00:01:22,298 Despite these drawbacks, virtual machines made it much easier to build 23 00:01:22,298 --> 00:01:27,800 reproducible environments for apps to run on, so they exploded in popularity. 24 00:01:27,800 --> 00:01:31,112 And in 2010, a software project named Vagrant came along, 25 00:01:31,112 --> 00:01:33,578 that promised to automate the creation of VMs. 26 00:01:33,578 --> 00:01:38,280 Vagrant allowed developers to build new VMs using a configuration file 27 00:01:38,280 --> 00:01:42,900 that specified an OS and software packages to install. 28 00:01:42,900 --> 00:01:47,300 But Vagrant still suffered from the imparent problem of virtual machines, 29 00:01:47,300 --> 00:01:51,050 distributing applications was still difficult, it wasn't practical to 30 00:01:51,050 --> 00:01:55,710 pass the VM from developer to developer or developer to customer. 31 00:01:55,710 --> 00:01:58,320 Anyone who wanted to work on Vagrant VM had 32 00:01:58,320 --> 00:02:01,770 run the initial bill to create their VM from scratch. 33 00:02:01,770 --> 00:02:06,280 That was the situation when Docker and the concept of containers arrived in 2013. 34 00:02:06,280 --> 00:02:09,059 The contents of Docker containers run directly on 35 00:02:09,059 --> 00:02:10,987 top of the host operating system. 36 00:02:10,987 --> 00:02:15,360 Unlike a virtual machine where they run on top of a guest operating system. 37 00:02:16,410 --> 00:02:19,250 Eliminating that guest OS and emulated hardware 38 00:02:19,250 --> 00:02:23,540 makes Docker containers much more lightweight than virtual machines. 39 00:02:23,540 --> 00:02:27,530 A Docker still offers many of the same benefits of Virtual Machines, 40 00:02:27,530 --> 00:02:31,830 because they're isolated in a container, the services running in docker containers 41 00:02:31,830 --> 00:02:35,160 can't interfere with each other, or with services on the host. 42 00:02:35,160 --> 00:02:37,460 Because there's no need for a full guest OS, 43 00:02:37,460 --> 00:02:40,011 docker containers offer many benefits over VMs. 44 00:02:40,011 --> 00:02:43,345 They start up faster, because you don't have to wait for 45 00:02:43,345 --> 00:02:45,128 a whole separate OS to load. 46 00:02:45,128 --> 00:02:48,600 You can re-use systems resources more efficiently. 47 00:02:48,600 --> 00:02:52,214 A virtual machine, usually has to receive some parts of the host resources and 48 00:02:52,214 --> 00:02:54,855 can't release them when it's not actively using them. 49 00:02:54,855 --> 00:02:58,169 Docker containers can free resources they are not using. 50 00:02:58,169 --> 00:03:02,776 Containers can usually take of the hard role in the host machine and 51 00:03:02,776 --> 00:03:04,600 ways a VM can. 52 00:03:04,600 --> 00:03:09,680 For example a VMK usually use the GPU to run codes but a container is up 53 00:03:09,680 --> 00:03:14,250 can make full use of it, and there's less redundancy with containers. 54 00:03:14,250 --> 00:03:18,860 Whereas VMs usually need the entire guess OS in order to run successfully, 55 00:03:18,860 --> 00:03:24,298 containers runs strip down versions of the OS with unnecessary parts removed. 56 00:03:24,298 --> 00:03:27,766 That means you can run more containers on the same host than you can with VMs. 57 00:03:27,766 --> 00:03:31,080 There's one limitation you should be aware of. 58 00:03:31,080 --> 00:03:34,316 Depending on the app you're running a container may not be having faster than 59 00:03:34,316 --> 00:03:35,171 a virtual machine. 60 00:03:35,171 --> 00:03:38,210 Containers usually start up faster than VMs though so 61 00:03:38,210 --> 00:03:41,121 you'll still see a speed benefit from switching. 62 00:03:41,121 --> 00:03:45,448 Docker's architecture has significant differences from traditional virtual 63 00:03:45,448 --> 00:03:47,270 machine architecture. 64 00:03:47,270 --> 00:03:51,450 Docker runs containers on top of light weight virtualized environments without 65 00:03:51,450 --> 00:03:53,740 fully virtualized in the home machine. 66 00:03:53,740 --> 00:03:57,430 Because docker doesn't virtualizing entire OS, it can run much quicker and 67 00:03:57,430 --> 00:04:00,620 be far more affordable than a traditional VM. 68 00:04:00,620 --> 00:04:05,390 Both virtual machines and containers run on top of a host operating system. 69 00:04:05,390 --> 00:04:10,410 To run virtual machines, the host OS runs software called a hypervisor. 70 00:04:10,410 --> 00:04:14,870 A hypervisor manages the life cycle of VMs, starting and stopping them as needed, 71 00:04:14,870 --> 00:04:17,420 managing their resources and keeping the whole 72 00:04:17,420 --> 00:04:21,198 setup secure by isolating the VMs from the host OS and from each other. 73 00:04:21,198 --> 00:04:25,456 An entire guest operating system runs within each virtual machine, and 74 00:04:25,456 --> 00:04:30,930 your apps dependencies as well as the app itself are run within the guest OS. 75 00:04:30,930 --> 00:04:32,096 Contrast this with Docker, 76 00:04:32,096 --> 00:04:34,437 where containers are run by the Docker Daemon software. 77 00:04:34,437 --> 00:04:39,410 Docker containers omit most of the guest OS except for a few packages. 78 00:04:39,410 --> 00:04:43,380 Meaning most of the container resources are devoted to your apps dependencies and 79 00:04:43,380 --> 00:04:44,850 the app itself. 80 00:04:44,850 --> 00:04:48,250 Docker doesn't have to run the entire guest OS to run an app, 81 00:04:48,250 --> 00:04:51,830 it simply share the host resources like processors, memory and 82 00:04:51,830 --> 00:04:54,440 networking devices between each container. 83 00:04:54,440 --> 00:04:58,420 Even better Docker does an exclusively hold the resources of the host OS. 84 00:04:59,570 --> 00:05:03,150 When resources are released from a container other Docker containers can use 85 00:05:03,150 --> 00:05:05,120 those same resources. 86 00:05:05,120 --> 00:05:09,030 Rather than entire virtual machines, it's simpler to think of containers of 87 00:05:09,030 --> 00:05:12,640 very heavy processes which the Docker components manage. 88 00:05:12,640 --> 00:05:18,030 This is what makes Docker a faster and better way to deploy absent services. 89 00:05:18,030 --> 00:05:21,880 So that's how Docker containers differ from virtual machines. 90 00:05:21,880 --> 00:05:24,870 Up next we'll look at the details of how Docker works.