1 00:00:04,720 --> 00:00:09,910 ‫Requirements for this lecture are that you understand what an image is and that you've done a little 2 00:00:09,910 --> 00:00:12,510 ‫bit of work with containers. 3 00:00:13,150 --> 00:00:19,600 ‫In this lecture, we're going to take a quick tour around Docker Hub and get to know a few of its basic 4 00:00:19,600 --> 00:00:26,710 ‫features. Then we'll kind of discuss the difference between an official image and maybe other just 5 00:00:26,710 --> 00:00:30,850 ‫as good images, and how to tell the difference between a good image and a bad image. 6 00:00:31,900 --> 00:00:38,020 ‫Then I'll show a little bit around downloading images and how you can see the different tags that 7 00:00:38,020 --> 00:00:42,320 ‫they'll use and the difference between an Alpine image and other image options. 8 00:00:43,340 --> 00:00:44,030 ‫... 9 00:00:44,210 --> 00:00:50,330 ‫You should have signed into hub.docker.com. When you sign in your default home page is your 10 00:00:50,330 --> 00:00:54,800 ‫dashboard, which will show you all of your repositories, public and private. 11 00:00:54,800 --> 00:00:58,150 ‫You're not going to have any yet, but you can see I have some here. 12 00:00:58,150 --> 00:00:59,060 ‫They're all public. 13 00:00:59,090 --> 00:01:09,920 ‫I have one private. For now let's go to the top and search nginx. What we'll get back is the 14 00:01:09,920 --> 00:01:16,400 ‫search results of Docker Hub and you'll see that there's a lot. I could scroll for pages and pages. 15 00:01:17,000 --> 00:01:21,590 ‫One of the challenges is there's 15,000 images of Nginx. 16 00:01:21,740 --> 00:01:22,730 ‫That's a lot. 17 00:01:22,760 --> 00:01:27,170 ‫So I pretty much just use one or two. 18 00:01:27,350 --> 00:01:28,510 ‫The official one right here, 19 00:01:28,520 --> 00:01:33,360 ‫you'll see at the top, has 10 million-plus pulls. 20 00:01:33,410 --> 00:01:38,430 ‫There's several characteristics to figuring out what's the right image. 21 00:01:38,510 --> 00:01:44,470 ‫Like me, you're going to start using the images for your workflow that are related to what you do 22 00:01:44,750 --> 00:01:48,240 ‫and you're going to get used to specific ones. You're going to like specific ones. 23 00:01:48,260 --> 00:01:51,470 ‫Typically, we always start with the official. 24 00:01:51,470 --> 00:01:56,340 ‫The official is going to be the only one with the word 'official' actually below it. 25 00:01:56,360 --> 00:02:02,290 ‫It will also be the only one where its name doesn't have a forward slash in it. 26 00:02:02,300 --> 00:02:08,240 ‫When you and I create images on Docker Hub, we have to create them with our account name in front 27 00:02:08,240 --> 00:02:08,730 ‫of them. 28 00:02:08,870 --> 00:02:15,440 ‫So when you look at all these other ones, these are account names slash image repository names. 29 00:02:15,610 --> 00:02:20,350 ‫It might be actually an organization slash nginx or something like that. 30 00:02:20,450 --> 00:02:27,770 ‫But the only ones that get to have just the name of the repo are considered official. Official images 31 00:02:28,040 --> 00:02:34,430 ‫are ones that Docker, Inc. actually has a team of people that help take care of them, ensure that they 32 00:02:34,430 --> 00:02:39,950 ‫have quality documentation, that they're well tested and that they're put together properly with Dockerfiles 33 00:02:39,950 --> 00:02:46,970 ‫that are obeying best practice rules. They usually work with the official team of that software who 34 00:02:46,970 --> 00:02:51,800 ‫actually makes it to ensure that it's doing all the things that it should be doing. 35 00:02:52,130 --> 00:02:54,260 ‫So I'm going to click on this one. 36 00:02:54,710 --> 00:02:59,440 ‫Let's look at a couple of things about Official Repositories. 37 00:02:59,690 --> 00:03:06,080 ‫Like I said before, you're often going to be using officials to start with and then eventually you may 38 00:03:06,080 --> 00:03:11,780 ‫find that you want to change it slightly or add a few things to it and you'll make your own images. 39 00:03:11,780 --> 00:03:13,930 ‫Official images are a great way to start. 40 00:03:14,180 --> 00:03:17,730 ‫One of the best things about official images is their documentation. 41 00:03:17,840 --> 00:03:21,110 ‫They're always really great at documenting how to make them work, 42 00:03:21,320 --> 00:03:28,730 ‫what options there might be, what environment variables, what's the default port and so on. 43 00:03:29,210 --> 00:03:34,940 ‫So back up at the top, you'll notice these versions. Versions are a common feature of official repositories. 44 00:03:34,940 --> 00:03:39,720 ‫You don't have to have versions in every image but official ones do. 45 00:03:39,740 --> 00:03:45,770 ‫Because most open-source software there's always at least a few official versions out in the wild that 46 00:03:45,920 --> 00:03:48,650 ‫are officially maintained and supported. 47 00:03:48,650 --> 00:03:55,970 ‫That's what we have here. We have the mainline 1.11 for Nginx and then 48 00:03:55,970 --> 00:04:01,220 ‫we have what's considered the stable branch of Nginx, which is 1.10. We can see the little name 49 00:04:01,220 --> 00:04:04,050 ‫here says stable jessie Dockerfile. 50 00:04:04,070 --> 00:04:04,520 ‫All right. 51 00:04:04,640 --> 00:04:05,820 ‫So let's break this down. 52 00:04:05,990 --> 00:04:12,710 ‫1.11.9, mainline, 1, 1.11 and latest. 53 00:04:12,710 --> 00:04:15,650 ‫Those are all tags. 54 00:04:15,650 --> 00:04:23,870 ‫When we start talking about images, images aren't necessarily named. Images are tagged. A version 55 00:04:23,870 --> 00:04:26,480 ‫of an image can actually have more than one tag. 56 00:04:26,480 --> 00:04:30,290 ‫We're going to dive into this a little bit later when we start making our own images and we can 57 00:04:30,290 --> 00:04:32,240 ‫play around with tagging. 58 00:04:32,780 --> 00:04:39,170 ‫But for now, if I wanted to actually download that specific image, and you remember earlier that we actually 59 00:04:39,170 --> 00:04:40,190 ‫already downloaded it, 60 00:04:40,190 --> 00:04:46,920 ‫so if I do a docker image ls, you'll see the three images that we've worked with so far on my machine. 61 00:04:47,090 --> 00:04:51,740 ‫You see the tag that says latest. Now latest is a special tag. 62 00:04:52,010 --> 00:04:57,760 ‫It doesn't necessarily guarantee it's always the latest commit in the repository. 63 00:04:58,190 --> 00:05:06,440 ‫What it usually means is you're getting the latest version of this product. In the official 64 00:05:06,440 --> 00:05:07,530 ‫repositories, 65 00:05:07,580 --> 00:05:13,130 ‫it's very well-defined and consistent so that if you didn't really care right now exactly what version 66 00:05:13,130 --> 00:05:21,320 ‫you wanted, you just wanted the most current, then you could just say docker pull nginx. It would 67 00:05:21,320 --> 00:05:26,960 ‫download the latest. You'll notice that it already knew I had it, it checked the SHA to make sure it 68 00:05:26,960 --> 00:05:30,500 ‫matched the one from Docker Hub and said "Hey I've already got this image, 69 00:05:30,500 --> 00:05:41,130 ‫it's up to date." What if I wanted to download docker image version 1.11.9? 70 00:05:41,270 --> 00:05:45,640 ‫It's going to go check and see what it needs to do to download that image 71 00:05:45,650 --> 00:05:49,740 ‫and it turns out it doesn't need to do anything because it's the exact same version. 72 00:05:49,940 --> 00:05:51,610 ‫That's what this line means up here. 73 00:05:51,650 --> 00:05:58,740 ‫I can refer to this 'main, latest' version right here by any of these tags. 74 00:05:58,790 --> 00:06:05,210 ‫The reason is if I just wanted to stay on the latest version of 1.0, whatever that might be for 75 00:06:05,460 --> 00:06:10,730 ‫Nginx, I could just specify a 1. If I wanted to be more specific when I downloaded images and I wanted 76 00:06:10,730 --> 00:06:19,340 ‫the most latest version of 1.11, then I could just type 1.11 like this and just 77 00:06:19,340 --> 00:06:22,970 ‫leave out the .9 and it would download that one. 78 00:06:23,030 --> 00:06:29,150 ‫But in my case, I actually specified the most specific of all the 1.11.9 which shows 79 00:06:29,150 --> 00:06:34,670 ‫the point release and that was just to ensure that I got the exact version I wanted. 80 00:06:34,670 --> 00:06:40,820 ‫So in your software, a best practice is when you're going to production and you're actually testing software 81 00:06:40,820 --> 00:06:42,900 ‫that you're going to be using for others, 82 00:06:42,950 --> 00:06:45,440 ‫you always want to specify the exact version. 83 00:06:45,440 --> 00:06:49,460 ‫It's rare that you really want your software to update automatically. 84 00:06:49,520 --> 00:06:53,380 ‫You usually want to control that process with some other DevOps tool. 85 00:06:56,150 --> 00:07:01,130 ‫But when you're developing or just testing something locally, it's super easy with official images to 86 00:07:01,130 --> 00:07:03,900 ‫just type in the name and just assume you're going to get the latest. 87 00:07:04,130 --> 00:07:06,090 ‫So you'll notice here there's other ones. 88 00:07:06,110 --> 00:07:13,120 ‫There's 1.11.9-alpine and these all have very similar names to the first one 89 00:07:13,130 --> 00:07:15,040 ‫but they all have the word alpine in them. 90 00:07:15,050 --> 00:07:21,740 ‫We're going to get into base images and distributions later, but just for now, Alpine is actually 91 00:07:21,740 --> 00:07:24,210 ‫a distribution of Linux that's very very small. 92 00:07:24,230 --> 00:07:31,670 ‫It's actually less than 5MB in size I believe. This version will actually mean that it comes from 93 00:07:31,880 --> 00:07:39,710 ‫a base image of Alpine, keeping it very small and light, whereas the default one or the latest image actually 94 00:07:39,710 --> 00:07:45,380 ‫comes from jessie, which is a Debian distribution. It's a little larger in size probably a little 95 00:07:45,380 --> 00:07:47,640 ‫bit over 100MB. 96 00:07:47,760 --> 00:07:50,380 ‫In fact, we can actually go over here and we can look. 97 00:07:50,460 --> 00:07:54,720 ‫So nginx 182MB right here. 98 00:07:54,800 --> 00:08:06,730 ‫If I want to download that exact version of the Alpine, I can say 1.11.9-apline 99 00:08:09,370 --> 00:08:17,340 ‫and then do docker image ls and you'll see that the alpine version is actually only 54MB 100 00:08:17,590 --> 00:08:21,730 ‫and the latest version is 182MB. 101 00:08:21,730 --> 00:08:26,740 ‫You'll also notice that the three versions that I've downloaded all have the same image ID because 102 00:08:26,740 --> 00:08:34,830 ‫the image ID is based upon the cryptographic SHA of each image in Docker Hub. 103 00:08:34,870 --> 00:08:40,510 ‫So this isn't actually three different copies of 128MB images. 104 00:08:40,510 --> 00:08:41,950 ‫It's actually a little deceiving. 105 00:08:41,950 --> 00:08:48,430 ‫It's really just three tags of the exact same image ID and it's only total ticking up 182MB 106 00:08:48,430 --> 00:08:53,930 ‫and these are just two other lines showing the same image ID with different tags associated to it. 107 00:08:54,310 --> 00:08:56,550 ‫But enough about tags and versions for now. 108 00:08:56,710 --> 00:08:57,920 ‫Let's check a few more things out 109 00:08:57,920 --> 00:09:05,030 ‫in Docker Hub. If I go back up to nginx in the search bar and search for nginx again, you'll see 110 00:09:05,060 --> 00:09:09,100 ‫again that there's a lot of other options and these can be made by anyone. 111 00:09:09,290 --> 00:09:13,820 ‫You can create your own custom Nginx version and because it's open source software and free to 112 00:09:13,820 --> 00:09:18,080 ‫distribute, you can put it back up here and offer it up to the public. 113 00:09:18,080 --> 00:09:23,330 ‫This is very similar to the model of GitHub where they allow you to store open source software and 114 00:09:23,330 --> 00:09:27,510 ‫you can fork other people's software and also offer it up. 115 00:09:27,650 --> 00:09:29,180 ‫The same thing goes here. 116 00:09:29,240 --> 00:09:35,120 ‫You can use other people's images and download them, make them your own, re-upload them. 117 00:09:35,180 --> 00:09:41,840 ‫So if I ever want to consider not using an official repository, what I usually look for is a number 118 00:09:41,840 --> 00:09:49,150 ‫of stars and a number of polls because a popular repository, to me, tends to establish trust. 119 00:09:49,160 --> 00:09:53,960 ‫I always recommend you download and inspect the software before you use it. Look in their Dockerfile 120 00:09:53,960 --> 00:09:59,060 ‫and hopefully they'll have an open source repository that you can go look at exactly how they 121 00:09:59,060 --> 00:10:00,480 ‫made that image. 122 00:10:00,560 --> 00:10:08,090 ‫A good indication is when you see things that have five million pulls on them and 945 stars; clearly 123 00:10:08,090 --> 00:10:12,890 ‫there's something interesting about this package and why so many people are choosing it rather than 124 00:10:12,890 --> 00:10:14,220 ‫using the official image. 125 00:10:16,320 --> 00:10:20,370 ‫You can come in here and look at their repository. 126 00:10:20,430 --> 00:10:26,670 ‫You can actually see over on the right that he is linked to his GitHub repository where the actual 127 00:10:26,670 --> 00:10:33,300 ‫open source software is that builds this image so that you can go and inspect it; and, possibly download 128 00:10:33,390 --> 00:10:36,290 ‫the actual source code outside of an image. 129 00:10:36,330 --> 00:10:41,610 ‫But, he clearly has done something with this Nginx image that makes it better than the official 130 00:10:41,610 --> 00:10:43,520 ‫default. 131 00:10:43,530 --> 00:10:48,750 ‫A couple more things. On the top bar, you'll see Explore. Explore 132 00:10:48,760 --> 00:10:53,980 ‫just gives you a summary of all the official images and you can peruse through them and, trust 133 00:10:53,980 --> 00:10:58,750 ‫me, there's a lot. In fact, in the resources for this section, 134 00:10:58,840 --> 00:11:05,500 ‫you'll find a link to the actual list of official images and under 'library,' 135 00:11:05,500 --> 00:11:10,050 ‫this is where all the official images and their Dockerfiles live. 136 00:11:10,190 --> 00:11:18,200 ‫You can see there's a lot. As a quick recap, in this lecture we talked about Docker Hub and how it's 137 00:11:18,200 --> 00:11:22,400 ‫similar to being the apt package manager for Containers, 138 00:11:22,400 --> 00:11:26,650 ‫Then how to recognize official images and how to use them. 139 00:11:27,080 --> 00:11:33,090 ‫Then I helped you figure out how to determine a good public image from maybe a not-so-good one. 140 00:11:33,620 --> 00:11:40,080 ‫Then a few tips about base images and how Alpine ones are typically smaller than their Debian counterparts. 141 00:11:40,190 --> 00:11:43,590 ‫So we're going to use these skills in the rest of this section.