1 00:00:00,960 --> 00:00:05,370 Before we move on there's just one last little quick thing though and show you around this entire image 2 00:00:05,370 --> 00:00:06,590 building process. 3 00:00:06,630 --> 00:00:10,740 Now what I'm going to show you inside this section is not something that you're probably gonna do very 4 00:00:10,740 --> 00:00:16,110 often or ever really but it's something I thought you might find a little bit interesting and help you 5 00:00:16,110 --> 00:00:21,240 get a little bit of a better handle on the relationship between an image and a container. 6 00:00:21,240 --> 00:00:25,530 When we were going over the flow of actions that occurred while we were building the image we spoke 7 00:00:25,530 --> 00:00:30,450 about how we take an image from the previous step we create a container out of it we do something with 8 00:00:30,450 --> 00:00:36,360 that container and we then essentially create an image out of that running container or that kind of 9 00:00:36,360 --> 00:00:40,020 very temporally temporary container that was created. 10 00:00:40,020 --> 00:00:45,600 So at this point you and I know very well that we use images to create containers but based on everything 11 00:00:45,600 --> 00:00:50,420 that we've been talking about in this section it sure seems like the opposite is kind of true as well. 12 00:00:50,430 --> 00:00:55,320 It seems like we can kind of take a container and generate an image out of it as well. 13 00:00:55,320 --> 00:00:57,000 And that actually is correct. 14 00:00:57,090 --> 00:01:03,330 You and I can manually create a container run some commands inside of it or change its file system and 15 00:01:03,330 --> 00:01:07,970 then generate a usable image that we can then use at some point in the future. 16 00:01:08,040 --> 00:01:14,010 In other words we can kind of very manually do the same thing that our darker file does. 17 00:01:14,070 --> 00:01:20,670 We can create a container run a command like say KPK ad read this right here and then generate an image 18 00:01:20,760 --> 00:01:21,630 out of that. 19 00:01:21,630 --> 00:01:23,340 I want to very quickly show you how that would look. 20 00:01:23,340 --> 00:01:26,510 But again I really don't expect you to do this on your own personal project. 21 00:01:26,550 --> 00:01:30,610 I'm just showing you this as kind of something you might find interesting. 22 00:01:30,810 --> 00:01:34,710 So let's try to kind of emulate the docker file that we just put together. 23 00:01:34,770 --> 00:01:38,480 We're going to create a new container manually out of the Alpine image. 24 00:01:38,520 --> 00:01:40,800 We're then going to install red lights on it. 25 00:01:40,800 --> 00:01:46,000 We're then going to set up a default command and generate a usable image that can be used in the future. 26 00:01:46,020 --> 00:01:48,840 Essentially everything that our Docker file just did. 27 00:01:49,170 --> 00:01:54,720 So at my terminal I can execute Docker run and we're gonna start up a shell inside of here so that we 28 00:01:54,720 --> 00:01:56,850 can run a couple of commands inside of it. 29 00:01:56,880 --> 00:02:03,990 So going to put on the I.T. flag I'll put on Alpine as our image and then the command that I want to 30 00:02:03,990 --> 00:02:07,390 execute inside there is a safe to start up a shell. 31 00:02:07,890 --> 00:02:13,140 So then I get presented with a command prompt right here that is inside of that running container. 32 00:02:13,410 --> 00:02:20,750 And so inside that container I'm going to manually install redness by running a P.K. add dash dash updates. 33 00:02:20,780 --> 00:02:22,830 Red is like so. 34 00:02:22,890 --> 00:02:29,430 So we now have a running container where we have modified its file system and a file system has now 35 00:02:29,580 --> 00:02:32,240 seen the installation of reticence. 36 00:02:32,280 --> 00:02:34,020 So we've got the running container. 37 00:02:34,170 --> 00:02:40,020 I'm now going to open up a second terminal window and inside of here I'm going to run a command using 38 00:02:40,020 --> 00:02:41,420 the docker Seelye. 39 00:02:41,520 --> 00:02:47,730 That's going to essentially take a snapshot of that running container and assign a default command to 40 00:02:47,730 --> 00:02:51,210 it and generate an image out of the entire thing. 41 00:02:51,210 --> 00:02:58,680 So to do so I'll say first Docker P.S. to get the idea that running container and then we'll do Docker 42 00:02:59,090 --> 00:03:00,180 commit. 43 00:03:00,410 --> 00:03:05,840 I'm going to add on a dash C right here which is going to allow us to specify the default command. 44 00:03:06,330 --> 00:03:14,830 So I can say dash C and then I'll put on CMT double quotes inside the square brace red s dash server 45 00:03:15,250 --> 00:03:19,410 I'll close the double quotes or close the square brace and I'll close the single quote. 46 00:03:19,420 --> 00:03:24,400 So notice how we have a single quote single quote and double quotes around it. 47 00:03:24,400 --> 00:03:28,950 And then after all that I'll paste the idea of that running container. 48 00:03:29,060 --> 00:03:35,680 It's going to paste it in like so and the output is the idea of a new image that we just customized 49 00:03:35,800 --> 00:03:37,720 for our own uses. 50 00:03:37,720 --> 00:03:40,220 Now you'll notice that this is a really long idea right here. 51 00:03:40,240 --> 00:03:45,820 One shortcut that I haven't quite mentioned so far whenever you're making use of ideas or hashes in 52 00:03:45,820 --> 00:03:46,530 the darker world. 53 00:03:46,540 --> 00:03:48,340 You don't have to copy the entire thing. 54 00:03:48,640 --> 00:03:53,870 You can just copy a segment of the start and it's kind of assume that this is going to be unique enough. 55 00:03:53,920 --> 00:03:57,850 The Docker is going to take this and realize that oh you're probably talking about this very long idea 56 00:03:57,850 --> 00:03:58,840 right here. 57 00:03:58,840 --> 00:04:04,720 So going to copy it just an arbitrary number of leading characters here and then we'll do a doctor run 58 00:04:04,940 --> 00:04:05,690 that. 59 00:04:05,850 --> 00:04:10,090 And that's going to start up a new container out of the image that we just created. 60 00:04:10,360 --> 00:04:15,760 And inside that running container we already have redness installed in the default starting command 61 00:04:15,820 --> 00:04:17,410 will be to run red a server. 62 00:04:18,040 --> 00:04:23,410 So let's run that and we'll very quickly see all the typical output that we see from a running redis 63 00:04:23,440 --> 00:04:24,720 instance. 64 00:04:24,730 --> 00:04:24,970 All right. 65 00:04:25,000 --> 00:04:30,970 So like I said we basically just very manually created a container added a dependency to the container 66 00:04:31,610 --> 00:04:36,710 set up the default command and then generated an image out of all that again. 67 00:04:36,870 --> 00:04:41,830 You really don't want to use that practice in general if you don't use Docker commit in general you 68 00:04:41,830 --> 00:04:47,110 really want to use the docker file approach because it allows you to very easily rerun that series of 69 00:04:47,110 --> 00:04:48,290 steps again in the future. 70 00:04:48,340 --> 00:04:50,460 But again I just thought you might find it interesting how. 71 00:04:50,560 --> 00:04:56,350 Yes there really is a very kind of fluid relationship between containers and images. 72 00:04:56,350 --> 00:04:56,630 All right. 73 00:04:56,650 --> 00:05:00,150 So let's take another quick pause right here and we'll move on to the next section.