1 00:00:00,240 --> 00:00:03,120 ‫Let's get your hands dirty ‫for just a few minutes. 2 00:00:03,510 --> 00:00:08,715 ‫You're going to do some Docker commands to ‫run some basic applications with Docker. 3 00:00:09,195 --> 00:00:11,805 ‫And in order to do that, we have ‫a couple of set up requirements. 4 00:00:11,835 --> 00:00:16,695 ‫Now, in the next section, you're going ‫to learn about installing Docker on 5 00:00:16,695 --> 00:00:20,145 ‫your particular operating system, or ‫maybe on a server where you want to 6 00:00:20,415 --> 00:00:24,645 ‫run most of this course, but in this ‫video, before we do that, because 7 00:00:24,675 --> 00:00:27,585 ‫there's a process you have to go ‫through there's some reboots sometimes. 8 00:00:28,005 --> 00:00:31,215 ‫And before we do all that, let's ‫just use our browser and use a 9 00:00:31,215 --> 00:00:34,695 ‫free service from Docker to spin ‫up some containers on the internet. 10 00:00:35,329 --> 00:00:38,660 ‫This is play with Docker below me is mobi. 11 00:00:38,809 --> 00:00:42,679 ‫The Docker whale actually it's ‫Moby Dock is his full name. 12 00:00:43,039 --> 00:00:45,830 ‫He also has Molly Dock, which ‫you will see around who is a pink 13 00:00:45,873 --> 00:00:48,403 ‫whale, and we're going to use this. 14 00:00:48,403 --> 00:00:53,533 ‫It's actually labs.play with ‫docker.com, which has dashes in it. 15 00:00:53,583 --> 00:00:54,783 ‫And I'll put it right below. 16 00:00:54,783 --> 00:00:55,723 ‫Did you can see that. 17 00:00:55,723 --> 00:00:58,803 ‫So go to type that in, but in order ‫to log in there, you're going to 18 00:00:58,803 --> 00:01:01,053 ‫need to jump over to Docker Hub. 19 00:01:01,245 --> 00:01:03,705 ‫There's only really one account ‫with Docker and you need to go 20 00:01:03,705 --> 00:01:08,415 ‫over to hub that Docker dot com ‫to sign up for that free account. 21 00:01:08,625 --> 00:01:10,845 ‫Totally free allows you to. 22 00:01:11,390 --> 00:01:14,990 ‫Log in and upload images and open ‫source and do some things as well 23 00:01:14,990 --> 00:01:16,790 ‫as logging into play with Docker. 24 00:01:17,030 --> 00:01:19,760 ‫The only reason we need a login ‫to use play with Docker is just to 25 00:01:19,760 --> 00:01:23,930 ‫prevent people on the internet from ‫misusing the free service, because 26 00:01:24,140 --> 00:01:25,670 ‫this is why we can't have nice things. 27 00:01:26,390 --> 00:01:28,650 ‫So jump over to hub.docker.com. 28 00:01:28,910 --> 00:01:29,570 ‫Fill it out. 29 00:01:29,570 --> 00:01:33,780 ‫You really only need your email ‫address, a Docker ID or your username. 30 00:01:33,900 --> 00:01:36,510 ‫That's important because whenever ‫you're logging in, you're always 31 00:01:36,510 --> 00:01:40,950 ‫going to use your Docker ID and your ‫password, not your email address. 32 00:01:41,280 --> 00:01:42,480 ‫So fill that out. 33 00:01:42,480 --> 00:01:44,790 ‫Remember your ID and your password. 34 00:01:45,180 --> 00:01:49,050 ‫Jump back over to play ‫with Docker's website. 35 00:01:49,470 --> 00:01:51,540 ‫And you're going to sign ‫in with the login button. 36 00:01:51,710 --> 00:01:55,190 ‫So pause this video, go do all that ‫and come back here and push play. 37 00:01:56,190 --> 00:01:56,610 ‫All right. 38 00:01:56,610 --> 00:01:58,770 ‫Do you have your Docker ‫ID and your password? 39 00:01:58,980 --> 00:02:01,230 ‫You're going to be using that ‫throughout this course for various 40 00:02:01,230 --> 00:02:04,140 ‫things, but for now, we're going ‫to use it to log in, to play with. 41 00:02:06,025 --> 00:02:09,715 ‫And over on the labs.play ‫with Docker website. 42 00:02:10,135 --> 00:02:13,735 ‫When you scroll down to log in, if you've ‫logged in, you will see the start button 43 00:02:13,735 --> 00:02:20,065 ‫there, green not blue, you click that and ‫it whisks you away to an interface that 44 00:02:20,065 --> 00:02:25,435 ‫in the background is going to allow you ‫to spin up multiple Docker instances on 45 00:02:25,435 --> 00:02:27,985 ‫the internet using real cloud services. 46 00:02:27,985 --> 00:02:29,575 ‫That Docker is maintaining for us. 47 00:02:30,575 --> 00:02:34,745 ‫So if you click on add new ‫instance over here on the left, 48 00:02:35,745 --> 00:02:38,325 ‫right there, click on that. 49 00:02:38,325 --> 00:02:40,605 ‫And we're only going to create ‫one instance for now later in the 50 00:02:40,605 --> 00:02:43,695 ‫course, we can actually create ‫multiple ones set up a cluster. 51 00:02:43,695 --> 00:02:44,325 ‫Do all that. 52 00:02:44,805 --> 00:02:47,835 ‫The one thing you have to remember is ‫that these are timed out at four hours, 53 00:02:47,835 --> 00:02:51,255 ‫so you can only use the same instances ‫for four hours and then they just go away. 54 00:02:52,255 --> 00:02:56,695 ‫So if we create, add new instance and we ‫give it a minute for it to spin up a new 55 00:02:56,695 --> 00:03:01,825 ‫Docker engine on a VM, and it's going ‫to give us some information at the top, 56 00:03:01,825 --> 00:03:06,895 ‫the IP address, the SSH, and we're not ‫gonna really use any of that just yet. 57 00:03:07,165 --> 00:03:10,405 ‫We want to focus on is down at the ‫bottom and I'm gonna zoom in so 58 00:03:10,405 --> 00:03:12,505 ‫you can see easier when I'm doing. 59 00:03:13,505 --> 00:03:17,495 ‫Now, if we do a Docker ‫space version command here. 60 00:03:19,270 --> 00:03:23,260 ‫You're going to get back to things, ‫a whole bunch of details about the 61 00:03:23,260 --> 00:03:27,910 ‫client and a whole bunch of details ‫about the engine or the Docker server. 62 00:03:28,910 --> 00:03:31,310 ‫And Docker is a two-part system. 63 00:03:31,550 --> 00:03:33,500 ‫You're going to be using ‫something like that. 64 00:03:33,500 --> 00:03:37,610 ‫Docker command line client, like we ‫just typed Docker space version, and 65 00:03:37,610 --> 00:03:43,380 ‫you're gonna be talking to the Docker ‫engine over one or more protocols. 66 00:03:43,380 --> 00:03:45,480 ‫You might be using sockets by default. 67 00:03:45,780 --> 00:03:49,020 ‫There's also the TCP connection ‫that can also be TLS. 68 00:03:49,260 --> 00:03:53,670 ‫And then you can also use an SSH tunnel if ‫you're going over random internet as well. 69 00:03:53,850 --> 00:03:56,370 ‫The point here is, is that ‫the commands you type are in 70 00:03:56,370 --> 00:03:58,110 ‫a client that has a version. 71 00:03:58,230 --> 00:04:01,350 ‫And that binary is just ‫called Docker on window. 72 00:04:01,350 --> 00:04:02,870 ‫That's technically docker.exe. 73 00:04:03,060 --> 00:04:05,670 ‫If you're on the windows side ‫of things, but in Linux, it's 74 00:04:05,670 --> 00:04:07,230 ‫just called Docker binary. 75 00:04:07,380 --> 00:04:09,090 ‫And then it's talking to the ‫engine in the background. 76 00:04:09,710 --> 00:04:12,170 ‫That's going to execute through the API. 77 00:04:12,350 --> 00:04:14,330 ‫All these things were typing into it. 78 00:04:15,330 --> 00:04:21,570 ‫Now, back at our shell, if we type a new ‫command and you can type the word clear to 79 00:04:21,600 --> 00:04:25,500 ‫get rid of everything else in the screen ‫and put your cursor right back at the top. 80 00:04:25,710 --> 00:04:30,030 ‫But once you're up there, you ‫can type Docker space run. 81 00:04:31,065 --> 00:04:35,355 ‫Space dash D for detach, which means ‫we want it to run in the background 82 00:04:35,835 --> 00:04:42,375 ‫space dash P, which means open up ‫a port and publish it on my host 83 00:04:42,375 --> 00:04:44,535 ‫IP so I can access it remotely. 84 00:04:45,195 --> 00:04:47,265 ‫And we're going to run an Apache server. 85 00:04:47,715 --> 00:04:52,185 ‫So we're going to choose port ‫8800 to listen to on our host. 86 00:04:52,515 --> 00:04:55,335 ‫And then we're going to tell it to ‫go into the container where Apache 87 00:04:55,335 --> 00:04:59,595 ‫is running on the default port ‫80, that Apache is listening on. 88 00:05:00,495 --> 00:05:02,085 ‫Then we're going to type in the image. 89 00:05:02,085 --> 00:05:04,345 ‫We want to run httpd. 90 00:05:05,760 --> 00:05:09,090 ‫That's the name of the Apache ‫demon running in the background. 91 00:05:09,420 --> 00:05:13,410 ‫And if we hit enter a whole lot ‫of stuff is happening all at once. 92 00:05:13,920 --> 00:05:18,060 ‫We're actually downloading the layers ‫of the image, just like you previously 93 00:05:18,060 --> 00:05:21,490 ‫learned that makes up this full image. 94 00:05:22,240 --> 00:05:24,990 ‫Then it's going to create the ‫networking, create the virtual 95 00:05:24,990 --> 00:05:26,850 ‫interface for the IP address. 96 00:05:26,850 --> 00:05:30,480 ‫It's going to create the empty file ‫system, load all these files from 97 00:05:30,480 --> 00:05:32,280 ‫the image into that file system. 98 00:05:32,490 --> 00:05:39,870 ‫And then finally, once that is all ‫created, it will start the httpd process 99 00:05:40,140 --> 00:05:43,620 ‫in its own little namespace where ‫it's basically the only thing running. 100 00:05:44,620 --> 00:05:48,820 ‫Now, if we wanted to prove that that ‫thing's actually working, we could 101 00:05:48,880 --> 00:05:53,530 ‫curl the localhost of this machine ‫we're on because we're running this 102 00:05:53,530 --> 00:05:57,240 ‫container on this machine, and that's ‫also where our command line is. 103 00:05:57,420 --> 00:06:04,040 ‫So we could type curl to use HTTP to ‫show us the webpage and we could curl 104 00:06:04,040 --> 00:06:09,950 ‫localhost 8800 because that's the ‫port we told it to listen on, on the 105 00:06:09,950 --> 00:06:14,540 ‫host IPs, all the host IPs, including ‫the public one and the localhost one 106 00:06:14,960 --> 00:06:15,680 ‫. ‫And it works. 107 00:06:15,860 --> 00:06:18,680 ‫It responds with the ‫default Apache web page. 108 00:06:19,680 --> 00:06:25,200 ‫And we can even see that that container ‫is running with a new command Docker PS. 109 00:06:25,950 --> 00:06:31,200 ‫So that shows us a list of all ‫the container processes running. 110 00:06:31,530 --> 00:06:33,090 ‫And in this case we only have the one. 111 00:06:33,640 --> 00:06:35,860 ‫Now, there's definitely ‫a lot of magic there. 112 00:06:36,160 --> 00:06:39,670 ‫And I mentioned a few of the things ‫it does, but there's a whole lot more. 113 00:06:39,770 --> 00:06:42,050 ‫We'll learn a lot more about ‫that throughout this course, 114 00:06:42,590 --> 00:06:44,420 ‫but let's start another one. 115 00:06:44,420 --> 00:06:48,590 ‫What happens if we run multiple ‫Apache servers, we could even run 116 00:06:48,590 --> 00:06:52,130 ‫multiple Apache servers of different ‫versions, all with single commands. 117 00:06:53,130 --> 00:06:58,440 ‫And because of the isolation and how ‫Docker ensures that one app in its 118 00:06:58,440 --> 00:07:02,760 ‫own container doesn't see or effect ‫another app in another container, we 119 00:07:02,760 --> 00:07:08,610 ‫can run that same command as long as ‫we're using a separate public port. 120 00:07:08,640 --> 00:07:10,410 ‫So that 8800 port. 121 00:07:10,770 --> 00:07:13,020 ‫We have to follow the rules of IPs, right? 122 00:07:13,200 --> 00:07:18,420 ‫We cannot use the same port on more ‫than one application at the same time. 123 00:07:18,720 --> 00:07:23,580 ‫So while the container itself ‫gets its own private IP address, 124 00:07:23,580 --> 00:07:25,020 ‫that listens on port 80. 125 00:07:25,350 --> 00:07:30,020 ‫It's when we use the dash P we're ‫saying, listen, on the interface. 126 00:07:30,020 --> 00:07:35,025 ‫The actual interfaces of my Linux ‫host and for the traffic from the 127 00:07:35,025 --> 00:07:40,005 ‫particular port I'm telling you into ‫that container where the Apache lives. 128 00:07:41,205 --> 00:07:48,405 ‫So if I simply hit the up arrow a few ‫times and I back up and type 8801 slightly 129 00:07:48,405 --> 00:07:54,345 ‫different port, then it will launch ‫me a second Apache service of which I 130 00:07:54,345 --> 00:07:56,745 ‫can see if I type in Docker PS again. 131 00:07:56,955 --> 00:07:58,235 ‫I now get back two. 132 00:07:58,905 --> 00:08:04,725 ‫Now, if I had left that 8800, the same, ‫I would actually get back an error 133 00:08:04,875 --> 00:08:07,095 ‫saying that the port is already in use. 134 00:08:07,625 --> 00:08:10,205 ‫Now, if we get a visualization ‫of what we just did. 135 00:08:10,890 --> 00:08:15,180 ‫Remember earlier, we talked about the ‫Linux features of Docker running on top. 136 00:08:15,420 --> 00:08:17,010 ‫And then we have this image. 137 00:08:17,160 --> 00:08:21,480 ‫When you do the Docker run command, it ‫downloads the image for you automatically. 138 00:08:21,630 --> 00:08:26,010 ‫You could have done a Docker pull ‫manually, but Docker run also does that 139 00:08:26,010 --> 00:08:27,990 ‫for you if the image doesn't exist. 140 00:08:28,290 --> 00:08:31,590 ‫So it pulls that down for us, and ‫then it creates a new container. 141 00:08:32,385 --> 00:08:34,065 ‫When we typed that Docker run command. 142 00:08:34,115 --> 00:08:37,685 ‫So it creates container ‫one with the httpd image. 143 00:08:38,015 --> 00:08:42,155 ‫And then when we type it a second time, ‫it creates a another container container 144 00:08:42,155 --> 00:08:47,615 ‫two, with its unique ID, running that ‫same image in a different process 145 00:08:47,615 --> 00:08:49,385 ‫space that's isolated from the first. 146 00:08:50,105 --> 00:08:55,775 ‫Now when we publish those ports, ‫we see that port 80 is the 147 00:08:55,775 --> 00:08:57,755 ‫port inside of each container. 148 00:08:57,755 --> 00:09:01,685 ‫That's listening on the private ‫IP, assigned to each container. 149 00:09:01,685 --> 00:09:02,465 ‫That's unique. 150 00:09:02,795 --> 00:09:06,245 ‫That is only accessible inside ‫of Docker's virtual networking, 151 00:09:06,395 --> 00:09:07,475 ‫which we'll talk about later. 152 00:09:07,805 --> 00:09:11,375 ‫But when we do that dash P we're ‫saying, Hey, take this container 153 00:09:11,645 --> 00:09:15,455 ‫and forward any traffic on the ‫public port that I tell you about. 154 00:09:16,040 --> 00:09:19,880 ‫From the host IP into this ‫container, which is why we can 155 00:09:19,880 --> 00:09:25,190 ‫assign external port 8800 to forward ‫traffic inside of container one 156 00:09:25,280 --> 00:09:30,500 ‫and then 8801 traffic externally ‫will then come into container two. 157 00:09:30,863 --> 00:09:35,753 ‫now this may seem a little like magic or ‫certainly a lot of automation, but it's 158 00:09:35,753 --> 00:09:40,703 ‫really just focusing on major features ‫of Linux and now windows that are sort of 159 00:09:40,733 --> 00:09:42,983 ‫adopting a lot of these Linux concepts. 160 00:09:43,420 --> 00:09:48,520 ‫And you may have heard of a few of these ‫namespaces and cgroups I listed before. 161 00:09:48,750 --> 00:09:51,940 ‫Veths or virtual Ethernet devices. 162 00:09:52,540 --> 00:09:58,600 ‫IPTABLES is like a firewall and ‫general IP packet, routing and control 163 00:09:58,600 --> 00:10:02,680 ‫interface, and then union mounts, which ‫is something that we use for getting 164 00:10:02,680 --> 00:10:08,105 ‫the file system with all these layers in ‫it, into the container at start to look 165 00:10:08,105 --> 00:10:12,125 ‫like its own unique file system that's ‫isolated from the rest of the host. 166 00:10:12,515 --> 00:10:16,115 ‫It seems like it's a lot of fancy, but ‫when you log into a container, if you 167 00:10:16,115 --> 00:10:20,001 ‫were to just shell into one of them, ‫it would just look like a normal Linux 168 00:10:20,001 --> 00:10:21,871 ‫file system with a lot less in it. 169 00:10:22,501 --> 00:10:24,541 ‫All right, that's it for this lecture. 170 00:10:24,601 --> 00:10:27,781 ‫I just wanted to give you a taste ‫of what we're going to do later. 171 00:10:28,081 --> 00:10:30,211 ‫You can always use the ‫play with Docker service. 172 00:10:30,211 --> 00:10:34,591 ‫It should be available 24-7, but in future ‫videos, we're going to learn how to get 173 00:10:34,591 --> 00:10:38,061 ‫Docker installed locally or installing ‫it on a real Linux server of your own. 174 00:10:38,341 --> 00:10:40,691 ‫So we're going to have fun ‫with that later for now. 175 00:10:40,691 --> 00:10:44,621 ‫You can click close session in ‫the top left and that will shut 176 00:10:44,621 --> 00:10:47,621 ‫down the containers, free up the ‫resources for someone else to 177 00:10:47,621 --> 00:10:49,481 ‫use this wonderful free resource. 178 00:10:49,571 --> 00:10:50,261 ‫Thanks Docker. 179 00:10:50,561 --> 00:10:51,041 ‫See you soon.