1 00:00:01,290 --> 00:00:06,030 In this section we're going to start to really get a better idea of what was really occurring on our 2 00:00:06,030 --> 00:00:10,900 terminal when we executed that docker build command. 3 00:00:10,900 --> 00:00:14,920 We're going to walk through each of these steps and not really analyze the structure of each of them 4 00:00:14,950 --> 00:00:19,120 but really analyze the effect that they had on the image that we were building. 5 00:00:19,210 --> 00:00:24,160 So to get started I first want to talk a little bit about the output that we saw in our terminal when 6 00:00:24,160 --> 00:00:26,530 we executed the docker build command. 7 00:00:26,530 --> 00:00:27,560 So first things first. 8 00:00:27,700 --> 00:00:29,160 Why do we use Docker built. 9 00:00:29,170 --> 00:00:31,720 Well this is a new command that we have not been used before. 10 00:00:31,720 --> 00:00:33,250 Tied to the docker CLIA. 11 00:00:33,670 --> 00:00:36,980 Remember what we said a little bit ago when we create our Docker file. 12 00:00:37,000 --> 00:00:42,460 We then feed it into the docker client which turns around and gives your file off to the docker server 13 00:00:42,730 --> 00:00:46,000 and that's what builds your usable image. 14 00:00:46,000 --> 00:00:52,600 So when we ran Docker Bill dot that was us giving our Docker file off to the docker CLIA that built 15 00:00:52,600 --> 00:00:56,950 command is what we used to take a docker file and generate an image out of it. 16 00:00:57,160 --> 00:01:03,670 The dot right here is specifying what is called the build context the build context is essentially the 17 00:01:03,670 --> 00:01:07,000 set of files and folders that belong to our project. 18 00:01:07,030 --> 00:01:11,770 It's a set of files and folders that we want to kind of encapsulate or wrap in this container and we'll 19 00:01:11,770 --> 00:01:16,690 see some better examples of exactly what the build context is used for later on throughout the course 20 00:01:16,750 --> 00:01:22,250 as our Docker builds start to get a little bit more complex after running that command. 21 00:01:22,270 --> 00:01:26,830 We then very quickly saw a whole bunch of output start to scroll on by the first thing I want you to 22 00:01:26,830 --> 00:01:32,260 notice here is that for every line of configuration we put into our Docker file we got an additional 23 00:01:32,290 --> 00:01:34,090 step added to this flow. 24 00:01:34,090 --> 00:01:38,610 So I see step one of three corresponds to the first line of our Docker file. 25 00:01:38,800 --> 00:01:42,260 I see it step two or three corresponding to the second line. 26 00:01:42,280 --> 00:01:44,660 And by that you can guess the third one down here. 27 00:01:44,770 --> 00:01:50,830 Step three of three correspondent to the third line of the docker file now with the very first step 28 00:01:50,860 --> 00:01:56,010 where we said from Alpine the first thing that occurred was the docker server looked at our local build 29 00:01:56,020 --> 00:02:02,290 cash and it check to see if it has ever downloaded an image called Alpine before in our case it probably 30 00:02:02,290 --> 00:02:02,890 hasn't. 31 00:02:02,890 --> 00:02:07,480 So the first thing that occurred was the docker server reached out to the Docker Hub which you'll recall 32 00:02:07,480 --> 00:02:11,210 is a repository of existing Docker images that are free for public use. 33 00:02:11,350 --> 00:02:15,210 And it downloaded that image the image called Alpine. 34 00:02:15,550 --> 00:02:20,380 So pull complete means Yep it was successfully downloaded and well it really tells you that very clearly 35 00:02:20,380 --> 00:02:24,180 right here it downloaded newer image for Alpine latest. 36 00:02:24,240 --> 00:02:26,110 So that for separate they're kind of boring. 37 00:02:26,110 --> 00:02:30,640 We basically just downloaded an initial starting image to use as a base. 38 00:02:30,640 --> 00:02:34,280 Things started to get a little bit more interesting on step number two right here. 39 00:02:34,330 --> 00:02:37,210 So there's a couple of lines of code or output right here. 40 00:02:37,240 --> 00:02:40,660 I want you to really take a very good look at. 41 00:02:40,660 --> 00:02:46,630 You'll notice the first line right here says running in and then an I.D. that's very key right there. 42 00:02:46,630 --> 00:02:52,090 And once you remember that for just a second and then a little bit lower you'll notice that it says 43 00:02:52,300 --> 00:02:58,540 removing intermediate container and it printed out the exact same I.D. that we saw back up there. 44 00:02:59,080 --> 00:03:03,250 So it looks like this idea right here is the I.D. of a container. 45 00:03:03,370 --> 00:03:04,710 But what container. 46 00:03:04,840 --> 00:03:06,310 We'll dive into that in just a second. 47 00:03:06,310 --> 00:03:10,030 When we look at a diagram that's going to Coote to kind of explain this flow. 48 00:03:10,030 --> 00:03:14,650 You'll notice that we also saw some very similar output down here for step three as well where it said 49 00:03:14,680 --> 00:03:20,870 running in blah blah blah and then very shortly after that removing intermediate container. 50 00:03:21,040 --> 00:03:24,810 One last thing I want to point out here is that four step number one up here. 51 00:03:24,820 --> 00:03:29,120 You'll notice that there is no kind of like intermediate container printout. 52 00:03:29,230 --> 00:03:35,020 So it appears that for every instruction that we added to the docker file the sites the first one it 53 00:03:35,020 --> 00:03:39,700 appears that some like container of sorts was created. 54 00:03:39,700 --> 00:03:44,920 So that mind is flip over to a diagram and really walk through what just occurred. 55 00:03:46,570 --> 00:03:47,540 All right. 56 00:03:47,560 --> 00:03:52,270 Now I know we're going through this stuff like really intense and in-depth but honestly getting a very 57 00:03:52,390 --> 00:03:57,520 fundamental or solid understanding of this docker build process is really going to help you understand 58 00:03:57,520 --> 00:03:58,330 Docker in general. 59 00:03:58,330 --> 00:04:01,040 That's why we're going through so much detail. 60 00:04:01,080 --> 00:04:01,360 OK. 61 00:04:01,600 --> 00:04:04,060 So in this diagram we've got a container on the right hand side. 62 00:04:04,120 --> 00:04:08,910 We've got the Alpine image on the bottom left and then our series of three commands over here. 63 00:04:08,920 --> 00:04:13,810 So the first thing we did was specify from Alpine and as we saw that basically went out and downloaded 64 00:04:13,840 --> 00:04:16,170 the Alpine image off of Docker Hub. 65 00:04:16,240 --> 00:04:20,830 Remember that an image has a file system snapshot and some start up commands. 66 00:04:20,860 --> 00:04:23,890 And at this point we don't really know what the start of the command for Alpine is. 67 00:04:23,890 --> 00:04:29,580 But you know we don't really care that much the next line was the run KPK. 68 00:04:29,630 --> 00:04:30,930 Add Update Read this. 69 00:04:31,000 --> 00:04:37,300 So here's exactly what happened behind the scenes when Docker server saw this line of configuration 70 00:04:37,300 --> 00:04:38,150 right here. 71 00:04:38,290 --> 00:04:41,590 It looked back at the last step that just occurred. 72 00:04:41,590 --> 00:04:48,610 So it looked back at this step the from Alpine step it looked at the image that came out of that previous 73 00:04:48,610 --> 00:04:49,350 step. 74 00:04:49,570 --> 00:04:53,670 The image that came out of the previous step was the Alpine image. 75 00:04:54,010 --> 00:04:59,460 Then on the run line right here it took that image and created a new container out of it. 76 00:04:59,470 --> 00:05:06,010 So in memory we've very temporarily got a brand new container created at the very start of Step number 77 00:05:06,010 --> 00:05:06,660 two. 78 00:05:06,790 --> 00:05:09,990 And that's what this running in blah blah blah right here means. 79 00:05:10,000 --> 00:05:15,070 It means that it created a temporary container out of the image that was sourced during the previous 80 00:05:15,070 --> 00:05:15,950 step. 81 00:05:16,060 --> 00:05:22,270 So it can kind of imagine that we took the entire file system snapshot from the Alpine image and we 82 00:05:22,270 --> 00:05:28,390 stuffed it into this very temporary container that was created just for the second step right here or 83 00:05:28,390 --> 00:05:35,030 the second instruction after creating this temporary container this command right here the commander 84 00:05:35,040 --> 00:05:43,550 we just added on was executed inside that container as its primary running process. 85 00:05:43,670 --> 00:05:45,180 So we took that run command. 86 00:05:45,320 --> 00:05:51,740 We took that line or that full command right there and we executed it as a process inside of the container. 87 00:05:51,740 --> 00:05:56,740 So this is this containers primary running process as we said in the last video. 88 00:05:56,750 --> 00:06:01,210 AP K is a package manager that is built into the Alpine image. 89 00:06:01,430 --> 00:06:04,060 So this command executed inside the container. 90 00:06:04,160 --> 00:06:08,490 And while it executed it went through the process of downloading reticence. 91 00:06:08,510 --> 00:06:09,900 That's what happened right here. 92 00:06:09,920 --> 00:06:15,230 It downloaded and installed readies in a couple of dependencies for readies so you can imagine that 93 00:06:15,230 --> 00:06:22,670 during that installation process we maybe got some like new folder on this containers harddrive right 94 00:06:22,670 --> 00:06:28,070 there maybe was something called like simply read us now you know I want this to represent the reddest 95 00:06:28,070 --> 00:06:28,670 program. 96 00:06:28,670 --> 00:06:32,840 It didn't install it in the root directory or anything like that but let's just imagine that a peak 97 00:06:32,870 --> 00:06:38,380 ad downloaded and installed is onto this containers a little hard drive right here. 98 00:06:38,450 --> 00:06:46,190 So we now have a container that has a file system snapshot that contains the newly installed copy of 99 00:06:46,190 --> 00:06:47,650 Redis. 100 00:06:47,660 --> 00:06:52,520 Now look at what happened immediately after that after that container or something after that package 101 00:06:52,580 --> 00:06:53,800 was installed. 102 00:06:53,840 --> 00:06:56,360 We then stopped that container. 103 00:06:56,450 --> 00:07:03,980 We took a file system snapshot of that container and then we stopped it entirely. 104 00:07:03,980 --> 00:07:08,360 So we're saying right here that temporary container that was just created we stop it and we then take 105 00:07:08,450 --> 00:07:15,610 its current file system snapshot and we save it as a temporary image with this idea right here. 106 00:07:15,650 --> 00:07:22,100 So the output of everything inside of Step number two is a new image that contains just the changes 107 00:07:22,100 --> 00:07:26,350 that we made during this step so we can now kind of imagine that this idea right here. 108 00:07:26,390 --> 00:07:29,460 This is the I.D. to a very temporary image. 109 00:07:29,600 --> 00:07:33,330 So I'm now going to update the image down here on the top left hand side. 110 00:07:33,380 --> 00:07:36,950 I'm going to say that is the 3 8 easy image. 111 00:07:37,070 --> 00:07:42,440 And inside that image it now has a installed copy of Rectus 112 00:07:45,240 --> 00:07:48,720 and we also threw away that intermediate container. 113 00:07:48,720 --> 00:07:51,420 So that is the end result of step number two. 114 00:07:51,510 --> 00:07:55,920 In total we created a temporary container out of the Alpine image. 115 00:07:55,920 --> 00:08:02,520 We executed this command inside that container and then we took that containers file system and saved 116 00:08:02,520 --> 00:08:04,520 it as a temporary image. 117 00:08:04,590 --> 00:08:10,770 So we now have this very temporary file system snapshot right here that has red is included. 118 00:08:10,770 --> 00:08:16,590 Then we move on to Step number three where we execute CMG right here so that you can imagine what happens 119 00:08:16,590 --> 00:08:18,710 here with CMT. 120 00:08:18,810 --> 00:08:22,870 We're going to look at the image that was generated during the previous step. 121 00:08:22,920 --> 00:08:29,520 So in this case the image that was taken from the previous step is this 3 8 easy image we create a new 122 00:08:29,640 --> 00:08:32,640 very temporary container out of it. 123 00:08:32,640 --> 00:08:37,890 And when we make that container we take the images file system snapshot and stuff it into this container 124 00:08:38,520 --> 00:08:44,280 and then with the ACM D this is setting the primary command or the primary process of the container. 125 00:08:44,280 --> 00:08:47,310 So the container does not actually execute read a server. 126 00:08:47,310 --> 00:08:48,890 It doesn't execute this command. 127 00:08:48,990 --> 00:08:54,390 It just tells the container hey like just so you know if you were to ever run for real you should be 128 00:08:54,390 --> 00:09:01,890 running read a server as your primary command so the container is told this is supposed to be your intermediate 129 00:09:01,900 --> 00:09:02,180 or or. 130 00:09:02,200 --> 00:09:08,160 This is supposed to be your primary command and then it shuts down that container and takes a snapshot 131 00:09:08,310 --> 00:09:11,810 of its file system and its primary command. 132 00:09:11,940 --> 00:09:15,600 So the end result is successfully built this idea right here. 133 00:09:15,600 --> 00:09:20,670 This is the final image that was created out of this entire series of steps. 134 00:09:20,850 --> 00:09:25,330 So in Step number three at the very end we remove the intermediate container. 135 00:09:25,440 --> 00:09:31,920 We take a snapshot of its file system and its primary command and then we save it as an output as an 136 00:09:31,920 --> 00:09:35,320 image with an idea of FC 6 0. 137 00:09:35,340 --> 00:09:36,570 So here's the container. 138 00:09:36,570 --> 00:09:44,590 The very temporary one we take a snapshot of its file system song and to put it over here and we also 139 00:09:44,590 --> 00:09:49,900 take a snapshot of it's running a primary command or is not running primary command but primary command 140 00:09:49,900 --> 00:09:52,920 that should be executed when the container starts up in the future. 141 00:09:53,200 --> 00:09:59,200 And so we specify the start up command as a server and then we save that entire thing as an image with 142 00:09:59,200 --> 00:10:09,000 the idea of FC 6 0 and so the end result is this right here the end result is our image with that I.D. 143 00:10:09,300 --> 00:10:15,510 that has our full file system snapshot with red is installed in a startup command that has been specified 144 00:10:16,460 --> 00:10:19,970 All right so at long last that is the full story. 145 00:10:19,980 --> 00:10:22,200 That is what happened with the docker file. 146 00:10:22,200 --> 00:10:26,970 Now the real takeaway that I want you to understand here is that basically along every step along the 147 00:10:26,970 --> 00:10:31,980 way not basically every step but really every step along the way with every additional instruction we 148 00:10:31,980 --> 00:10:36,110 essentially take the image that was generated during the previous step. 149 00:10:36,330 --> 00:10:38,440 We create a new container out of it. 150 00:10:38,610 --> 00:10:43,610 We execute a command in the container or make a change to its file system. 151 00:10:43,650 --> 00:10:45,570 We then look at that container. 152 00:10:45,570 --> 00:10:52,620 We take a snapshot of its file system and save it as an output for the next instruction along the chain. 153 00:10:52,620 --> 00:10:57,870 And then when there is no more instructions to execute the image that was generated during that last 154 00:10:57,870 --> 00:11:00,140 step is output from the entire process. 155 00:11:00,180 --> 00:11:03,830 As the final image that we really care about who. 156 00:11:04,200 --> 00:11:05,690 So that's a lot of information. 157 00:11:05,700 --> 00:11:08,730 So let's take a quick pause right here and we'll continue in the next section.