1 00:00:00,660 --> 00:00:03,930 In last section we spoke about how we make our own custom image. 2 00:00:03,930 --> 00:00:05,220 We create a docker file. 3 00:00:05,220 --> 00:00:09,690 We feed it into the docker server and that's going to eventually build a useful image that we can use 4 00:00:09,690 --> 00:00:12,210 to start up our own custom containers. 5 00:00:12,210 --> 00:00:17,570 And inside that Docker file we're gonna specify a base image run some commands and then eventually specify 6 00:00:17,580 --> 00:00:21,050 command to run when a container is created out of the image. 7 00:00:21,060 --> 00:00:24,720 So in this section we're gonna start working on our own custom Docker file. 8 00:00:25,200 --> 00:00:28,510 Let me first tell you about what we're going to be trying to build. 9 00:00:28,560 --> 00:00:34,620 So we are going to make a docker file that is going to create an image that's going to run red as server 10 00:00:34,680 --> 00:00:36,230 whenever it starts up. 11 00:00:36,300 --> 00:00:40,560 Now throughout this course we've already been making use of that red US image to start up red us on 12 00:00:40,560 --> 00:00:41,720 our local computer. 13 00:00:41,910 --> 00:00:47,760 But I want to show you how to build that thing from scratch or somewhat from scratch just to be precise. 14 00:00:48,150 --> 00:00:52,980 So this is going to be going to be the purpose of our Docker file and the image that we're going to 15 00:00:52,980 --> 00:00:54,280 create out of it. 16 00:00:54,300 --> 00:00:56,520 So let's get started right now. 17 00:00:56,520 --> 00:01:02,460 I'm going to first begin by flipping over to my terminal and I'm going to create a new working directory 18 00:01:02,460 --> 00:01:08,710 or kind of a project directory of sorts and I'm going to call it Rita's image. 19 00:01:09,080 --> 00:01:16,150 Like so now you can put this folder anywhere you want on your machine doesn't matter anywhere is good. 20 00:01:16,180 --> 00:01:22,490 I'll then change into that directory and then I'm going to start up my code editor inside that folder. 21 00:01:22,520 --> 00:01:27,020 Now quick note I am making use of visual studio code and I have configured it so that I could run it 22 00:01:27,020 --> 00:01:28,060 from the command line. 23 00:01:28,070 --> 00:01:31,400 So that is why I'm able to run code dot right here. 24 00:01:31,400 --> 00:01:35,750 If you have not gone through those same steps you will not be able to run that command and start up 25 00:01:35,750 --> 00:01:41,030 your editor essentially all you need to do right now is start up whatever code editor you like to use 26 00:01:41,120 --> 00:01:47,200 and open up that reddest image directory that we just created then inside of here. 27 00:01:47,360 --> 00:01:54,470 I want to make a new file called Docker file and notice how it has a capital D and it has no extension 28 00:01:55,010 --> 00:01:57,920 so there's no J us on here there's no shell. 29 00:01:57,920 --> 00:01:58,790 There's nothing like that. 30 00:01:58,790 --> 00:02:01,910 It is simply called Docker file. 31 00:02:01,910 --> 00:02:06,620 So then inside of here we're gonna write out a couple of comments to guide us through the process of 32 00:02:06,620 --> 00:02:12,520 creating our custom image and it's going to essentially follow this template of steps right here. 33 00:02:12,560 --> 00:02:16,430 So the first comment I'm gonna put down and notice how we create a comment by putting down the pound 34 00:02:16,430 --> 00:02:17,480 symbol. 35 00:02:17,480 --> 00:02:25,170 I'm going to say that I'm going to use an existing Docker image as a base I'm then going to download 36 00:02:25,260 --> 00:02:28,380 and install a dependency. 37 00:02:28,380 --> 00:02:37,440 And then finally I'm going to tell the image what to do when it starts as a container. 38 00:02:37,570 --> 00:02:41,990 All right now I'll be honest with you the way we're going to approach this darker file where it's going 39 00:02:41,990 --> 00:02:46,730 to write out all the code inside of here all the configuration we're going to use it to build our image 40 00:02:46,970 --> 00:02:50,930 and then we're going to come back and talk about all the configuration that we've written inside of 41 00:02:50,930 --> 00:02:51,440 here. 42 00:02:51,650 --> 00:02:55,970 To be honest it's a lot easier to understand the configuration that we're going to write after you've 43 00:02:55,970 --> 00:02:58,980 actually seen the process of creating an image. 44 00:02:59,060 --> 00:03:02,140 So a little bit of just blind copy pasting here. 45 00:03:02,200 --> 00:03:07,190 So just follow along and we'll very quickly come back and talk about the exact lines of code that we're 46 00:03:07,190 --> 00:03:08,280 adding it. 47 00:03:08,390 --> 00:03:16,030 So the first thing I'm going to write down is from Alpine then in the next section I'm going to add 48 00:03:16,210 --> 00:03:26,250 run a P.K. add dash dash update readies and then finally on the very bottom line here I'm going to add 49 00:03:26,310 --> 00:03:35,760 CMT a set of square brackets a set of double quotes and then inside there I'll put reddest dash server 50 00:03:35,850 --> 00:03:42,570 like so now I'm going to save this file I'm going to flip back over to my terminal. 51 00:03:42,860 --> 00:03:47,750 I'm going to make sure that I'm inside of that reddest dash image directory and I'm going to run the 52 00:03:47,750 --> 00:03:55,440 line run the command excuse me docker build dot don't forget the little dot on their nose how there's 53 00:03:55,440 --> 00:04:01,280 a little period so going to run that and then we're going to very quickly see a whole bunch of output 54 00:04:01,280 --> 00:04:06,230 start to stream along here and then eventually I see a message that says successfully built and then 55 00:04:06,350 --> 00:04:08,240 blah blah blah. 56 00:04:08,240 --> 00:04:14,630 Now we're going to copy this idea right here and then run Docker run and then I'll paste that idea in 57 00:04:15,840 --> 00:04:22,840 and execute this and then we're going to very quickly see all the kind of output here that we saw previously 58 00:04:22,900 --> 00:04:23,990 when we ran that Docker. 59 00:04:23,990 --> 00:04:29,570 So I mean the red is image and the last message I should see is ready to accept connections. 60 00:04:29,590 --> 00:04:29,890 OK. 61 00:04:29,920 --> 00:04:34,300 So we just went through the process of creating the docker file using it to build an image and we started 62 00:04:34,300 --> 00:04:38,700 that image up but we haven't really said anything about what really happened there. 63 00:04:38,710 --> 00:04:42,790 I'm going to stop the running container by pressing control see we're going to take a quick break come 64 00:04:42,790 --> 00:04:48,460 back the next section and talk about exactly what we just did inside this file and at the terminal. 65 00:04:48,490 --> 00:04:50,250 So quick break and I'll see you in just a minute.