1 00:00:00,000 --> 00:00:04,200 [Intro Music] 2 00:00:04,200 --> 00:00:05,850 Before going on, I need to perform 3 00:00:05,850 --> 00:00:07,860 some cleanup of my Docker setup 4 00:00:08,010 --> 00:00:09,750 because I have some cached images 5 00:00:09,750 --> 00:00:11,130 and some containers that were 6 00:00:11,130 --> 00:00:13,020 stopped. If you have clean Docker 7 00:00:13,020 --> 00:00:14,490 setup feel free to skip this 8 00:00:14,490 --> 00:00:15,990 lecture and move on to next one. 9 00:00:16,379 --> 00:00:17,970 All right, let me list 10 00:00:18,000 --> 00:00:20,490 containers here that were stopped 11 00:00:20,520 --> 00:00:23,820 'docker ps -a', and here I see 12 00:00:23,820 --> 00:00:26,430 bunch of stopped containers. And in 13 00:00:26,430 --> 00:00:27,660 order to remove all stopped 14 00:00:27,660 --> 00:00:29,310 containers, I could use command 15 00:00:29,340 --> 00:00:33,990 'docker container prune'. There is no 16 00:00:33,990 --> 00:00:35,520 short version of this command, 17 00:00:35,550 --> 00:00:37,590 that's why I'm using Container 18 00:00:37,620 --> 00:00:39,510 Management Command along with 'prune' 19 00:00:39,540 --> 00:00:43,680 sub command. Type 'Y' here, and all 20 00:00:43,710 --> 00:00:45,900 stopped containers were deleted. 21 00:00:46,290 --> 00:00:48,180 And now if I list containers using 22 00:00:48,180 --> 00:00:50,550 same command 'docker ps -a', I 23 00:00:50,550 --> 00:00:52,110 will not see any containers on the 24 00:00:52,110 --> 00:00:54,630 list. Great. Let me now list all 25 00:00:54,630 --> 00:00:56,730 images that I have before pulled 26 00:00:56,730 --> 00:00:58,440 from Docker Hub. For that I could 27 00:00:58,440 --> 00:01:00,510 use short command 'docker images', 28 00:01:00,900 --> 00:01:02,730 and here is a long list of images 29 00:01:02,760 --> 00:01:04,200 that I have used before in the 30 00:01:04,200 --> 00:01:07,170 previous long practice chapter. And 31 00:01:07,170 --> 00:01:09,720 I see such images as mysql, 32 00:01:09,720 --> 00:01:12,450 wordpress, httpd, redis, and so on. 33 00:01:12,840 --> 00:01:14,820 At the moment, those images are not 34 00:01:14,820 --> 00:01:16,620 used, and there are no containers 35 00:01:16,620 --> 00:01:18,510 created from those images, that's 36 00:01:18,510 --> 00:01:20,700 why I'm able to safely prune those 37 00:01:20,730 --> 00:01:23,130 images. And for that I could use 38 00:01:23,340 --> 00:01:25,890 'docker image prune' command. Let me 39 00:01:25,890 --> 00:01:27,810 first list all commands, sub 40 00:01:27,810 --> 00:01:29,850 commands of Docker Image Management 41 00:01:29,850 --> 00:01:31,950 Commands, 'docker image --help'; 42 00:01:32,550 --> 00:01:34,140 and here is this list of sub 43 00:01:34,140 --> 00:01:35,880 commands that you are able to use 44 00:01:35,910 --> 00:01:37,800 along with image management 45 00:01:37,800 --> 00:01:39,510 command. And here is 'prune' 46 00:01:39,510 --> 00:01:40,860 command. And with help of this 47 00:01:40,860 --> 00:01:43,020 command, you are able to remove 48 00:01:43,080 --> 00:01:45,330 unused images. Image is 49 00:01:45,330 --> 00:01:47,160 considered unused when there are 50 00:01:47,220 --> 00:01:49,710 no running or stopped containers 51 00:01:49,770 --> 00:01:51,390 that were created from this image. 52 00:01:52,050 --> 00:01:53,880 Great. Let me know list all 53 00:01:53,880 --> 00:01:55,830 possible options for 'prune' command, 54 00:01:55,920 --> 00:01:59,831 'docker image prune --help', 55 00:01:59,831 --> 00:02:02,490 and here are some options. 56 00:02:02,790 --> 00:02:05,040 And notice that with '-a' option, 57 00:02:05,100 --> 00:02:06,600 or '--all', this long 58 00:02:06,600 --> 00:02:08,880 version of this short command, you 59 00:02:08,880 --> 00:02:10,710 are able to, Remove all unused 60 00:02:10,740 --> 00:02:13,740 images not just dangling ones. It 61 00:02:13,740 --> 00:02:16,110 means that just with 'docker image 62 00:02:16,110 --> 00:02:18,390 prune' command, Docker will remove 63 00:02:18,420 --> 00:02:20,970 all the so called dangling images. 64 00:02:21,510 --> 00:02:23,580 An image is considered dangling 65 00:02:23,730 --> 00:02:25,740 when there is no corresponding 66 00:02:25,920 --> 00:02:27,690 version of this image at Docker 67 00:02:27,690 --> 00:02:29,880 Hub. For example, when you have 68 00:02:29,880 --> 00:02:31,440 pulled a specific image from Docker 69 00:02:31,440 --> 00:02:33,900 Hub, but afterwards, such image was 70 00:02:33,930 --> 00:02:35,880 removed from Docker Hub, but it 71 00:02:35,910 --> 00:02:38,040 remains in your local cache, this 72 00:02:38,070 --> 00:02:40,830 image is called dangling image. But 73 00:02:40,860 --> 00:02:42,960 I want to remove all unused images, 74 00:02:43,020 --> 00:02:45,240 and that's why I need to add '-a' 75 00:02:45,270 --> 00:02:47,430 option to 'docker image prune' 76 00:02:47,430 --> 00:02:50,910 command. Let's do that, 'docker image 77 00:02:51,060 --> 00:02:55,410 prune -a'. Yes. Notice that 78 00:02:55,440 --> 00:02:57,390 this will remove all images without 79 00:02:57,390 --> 00:02:59,670 at least one container associated 80 00:02:59,670 --> 00:03:01,530 to them. At the moment, I don't 81 00:03:01,530 --> 00:03:03,240 have any containers running or 82 00:03:03,270 --> 00:03:05,160 stopped. Right, let's press enter 83 00:03:05,160 --> 00:03:07,800 here. I need to cut out because 84 00:03:07,800 --> 00:03:09,240 Docker is removing several 85 00:03:09,270 --> 00:03:12,030 gigabytes of images. And finally, 86 00:03:12,060 --> 00:03:14,160 images were deleted. And in this 87 00:03:14,160 --> 00:03:16,890 output, I see a long list of logs, 88 00:03:16,950 --> 00:03:19,650 like deleted: sha256, and then 89 00:03:19,680 --> 00:03:21,870 comes the list of hexadecimal 90 00:03:21,870 --> 00:03:23,970 characters. And here in this 91 00:03:24,000 --> 00:03:26,160 output, I see a long list of 92 00:03:26,190 --> 00:03:29,250 such logs. Also, I see such logs 93 00:03:29,310 --> 00:03:32,460 as 'untagged: node: latest' or 'untagged: 94 00:03:32,490 --> 00:03:35,130 node@sha256', and then 95 00:03:35,130 --> 00:03:37,680 comes again SHA Hash. And again, 96 00:03:37,710 --> 00:03:40,260 this list is much longer than the 97 00:03:40,350 --> 00:03:42,450 amount of images I have used on 98 00:03:42,450 --> 00:03:44,520 this Docker machine. And the reason 99 00:03:44,520 --> 00:03:46,470 for that is that basically every 100 00:03:46,500 --> 00:03:49,620 image consists of multiple file 101 00:03:49,620 --> 00:03:51,900 system layers. And that's why 102 00:03:51,930 --> 00:03:53,940 Docker has removed corresponding 103 00:03:53,970 --> 00:03:56,070 file system layers instead of just 104 00:03:56,070 --> 00:03:58,140 removing images. That's why in this 105 00:03:58,170 --> 00:04:00,360 log output I see multiple lines, 106 00:04:00,570 --> 00:04:02,670 because every image may have 107 00:04:02,700 --> 00:04:05,970 multiple FS layers. For example, 108 00:04:06,000 --> 00:04:08,400 this busybox image had two layers, 109 00:04:08,430 --> 00:04:10,530 that's why here I see those two 110 00:04:10,560 --> 00:04:13,800 deleted lines. alpine image has 111 00:04:13,800 --> 00:04:15,990 only one, that's why here I see only 112 00:04:15,990 --> 00:04:19,170 this one deleted line. But no 113 00:04:19,170 --> 00:04:20,399 worries, we will talk about all 114 00:04:20,399 --> 00:04:22,290 those details a bit later. For now 115 00:04:22,320 --> 00:04:23,610 you need to understand that I have 116 00:04:23,610 --> 00:04:25,680 successfully deleted all images 117 00:04:25,709 --> 00:04:28,110 that were stored in my local cache. 118 00:04:28,410 --> 00:04:30,960 And now if I enter 'docker images' 119 00:04:30,960 --> 00:04:33,420 command, I will see nothing. There 120 00:04:33,420 --> 00:04:35,760 are no images in my local cache and 121 00:04:35,760 --> 00:04:37,680 we are able to go on. Next I will 122 00:04:37,680 --> 00:04:39,250 start from scratch and download 123 00:04:39,330 --> 00:04:41,470 very first, most simple hello-world 124 00:04:41,470 --> 00:04:42,750 container, and explain you 125 00:04:42,780 --> 00:04:44,430 what happens under the hood and 126 00:04:44,430 --> 00:04:46,020 what is the structure of that image 127 00:04:46,050 --> 00:04:47,580 that we will download. I will see 128 00:04:47,580 --> 00:04:49,010 you in the next lecture. Bye-Bye. 129 00:04:49,010 --> 00:04:51,114 [no audio]