1 00:00:00,720 --> 00:00:05,130 In last section we put together the core of the no Jesus web application. 2 00:00:05,130 --> 00:00:09,510 If you didn't follow along the last section and you just copy pasted the code just make sure that you've 3 00:00:09,510 --> 00:00:13,550 got your index out today as file in a package not just on file. 4 00:00:13,590 --> 00:00:18,320 You'll also want to make sure that you've got your terminal open inside of your project directory. 5 00:00:18,420 --> 00:00:22,860 And so if I list out my current files and folders I should see the indexed dot Jesus and package such 6 00:00:22,860 --> 00:00:24,560 a sum files. 7 00:00:24,580 --> 00:00:29,100 OK so we've got some source code here and now we need to figure out how we can wrap this all up inside 8 00:00:29,160 --> 00:00:30,850 of a docker container. 9 00:00:30,870 --> 00:00:35,490 I want to first begin by telling you a little bit about know James and how we're going to start up this 10 00:00:35,490 --> 00:00:36,800 application. 11 00:00:36,840 --> 00:00:42,600 So just in case you've never made use of note before two commands that you need to be aware of to install 12 00:00:42,600 --> 00:00:45,610 dependencies in start up this application. 13 00:00:45,610 --> 00:00:51,240 Anytime that we want to start up a node app we have to first install a set of dependencies and we can 14 00:00:51,240 --> 00:00:57,510 install all of our dependencies by running a command npm install inside of our project directory. 15 00:00:57,510 --> 00:01:03,240 This starts up a little program called NPM which is somewhat called colloquially known as the node package 16 00:01:03,240 --> 00:01:04,270 manager. 17 00:01:04,290 --> 00:01:08,100 This is going to run that program and install a couple of dependencies for us. 18 00:01:08,160 --> 00:01:13,350 And of course it assumes that NPM is installed on our local machine we're inside the container as the 19 00:01:13,350 --> 00:01:15,400 case may be. 20 00:01:15,510 --> 00:01:19,830 The other thing to be aware of is that we're going to have to eventually start our server up and to 21 00:01:19,830 --> 00:01:24,030 do so we're going to run the command NPM start at the terminal as well. 22 00:01:24,090 --> 00:01:27,690 And again this also kind of assumes that NPM is already installed. 23 00:01:28,560 --> 00:01:28,800 All right. 24 00:01:28,830 --> 00:01:33,260 So with all this in mind let's now start thinking about the docker file that we have to put together. 25 00:01:33,450 --> 00:01:38,160 Now this series of operations that we are going to put into the docker file is going to end up looking 26 00:01:38,160 --> 00:01:41,640 very similar to what we did in the last application. 27 00:01:41,640 --> 00:01:47,010 So in this somewhat complicated diagram our template that we're kind of following here for our Docker 28 00:01:47,010 --> 00:01:53,550 file is to specify a base image run some command to install some dependencies which definitely sounds 29 00:01:53,550 --> 00:01:58,950 like something we have to do and then specify the command to run on startup which as we just discussed 30 00:01:58,980 --> 00:02:06,210 is that NPM start thing now over when we are working on the reddest image we said from alpine to specify 31 00:02:06,210 --> 00:02:12,030 the base image we ran a B.K. at readies to install the dependency and then we set up the default command 32 00:02:12,060 --> 00:02:13,310 as red as server. 33 00:02:13,500 --> 00:02:18,030 And so it really seems like we have some very direct parallels this time around. 34 00:02:18,030 --> 00:02:23,310 I think that for the node application we could probably do a docker file that specifies Alpine as our 35 00:02:23,310 --> 00:02:24,450 base image. 36 00:02:24,450 --> 00:02:30,450 We can then run npm install to install all of our dependencies and then we can setup the default command 37 00:02:30,480 --> 00:02:35,170 of NPM start to run the server when the container first comes online. 38 00:02:35,250 --> 00:02:39,480 So we're going to take this type of approach right here by creating a doctor file and then essentially 39 00:02:39,480 --> 00:02:43,040 putting almost exactly these instructions inside of it. 40 00:02:43,140 --> 00:02:46,140 Now quick disclaimer just a quick disclaimer here. 41 00:02:46,200 --> 00:02:51,480 Remember I had said we're going to do a few things here slightly wrong just so you can see some very 42 00:02:51,480 --> 00:02:57,570 common error messages that you are just about guaranteed to see on your own personal projects. 43 00:02:57,600 --> 00:03:02,970 So maybe in this discussion or the series of steps I just described there might be something in here 44 00:03:03,150 --> 00:03:07,320 that doesn't quite line up with what's reality or what we really have to do. 45 00:03:07,470 --> 00:03:09,100 OK all right. 46 00:03:09,100 --> 00:03:10,160 So let's get started. 47 00:03:10,180 --> 00:03:13,930 I'm going to begin by making sure I've got my code Ed open. 48 00:03:14,080 --> 00:03:20,240 Based on that simple web directory and inside of here I'm going to make a new Docker file. 49 00:03:20,590 --> 00:03:26,630 Remember it's darker with a capital D and there is no file extension on there than inside of here. 50 00:03:26,650 --> 00:03:31,270 We're going to first specify our base image and just to be really complete. 51 00:03:31,300 --> 00:03:33,370 I'm going to add in some comments for these steps. 52 00:03:33,370 --> 00:03:36,370 Just to remind you what we're doing every step along the way. 53 00:03:36,400 --> 00:03:40,820 So I'll say specify a base image and you know what. 54 00:03:40,870 --> 00:03:46,350 Let's use that alpine image again it really seemed like it worked out last time for us. 55 00:03:46,360 --> 00:03:56,100 Next up we're going to install some dependencies to do so we will run the command npm install like I 56 00:03:56,100 --> 00:04:01,920 just said the NPM installed command is how we installed dependencies on a node J.S. Project and then 57 00:04:01,920 --> 00:04:08,970 finally we will set up a default command which we can do by running out CMT and then we put down a set 58 00:04:08,970 --> 00:04:14,880 of square brackets and then in a set of double quotes we separately list out all the parts of the command 59 00:04:14,940 --> 00:04:15,750 that we want to run. 60 00:04:15,750 --> 00:04:21,450 When the container is first created and so to start up our server we are probably going to want NPM 61 00:04:21,630 --> 00:04:23,260 start like so. 62 00:04:23,280 --> 00:04:28,210 Notice that I've got a comma between those two strings all right. 63 00:04:28,250 --> 00:04:29,480 I think this looks pretty good. 64 00:04:29,510 --> 00:04:32,300 It definitely looks very similar to what we did for reds. 65 00:04:32,330 --> 00:04:39,040 So let's now flip back over to our terminal and see what happens when we try to build this image. 66 00:04:39,230 --> 00:04:44,960 So I'm going to list out my files and folders and verify that I now see the docker file inside of here. 67 00:04:44,960 --> 00:04:51,740 And then remember to build an image we can run docker build and then we put the dot in there to specify 68 00:04:51,800 --> 00:05:00,760 the build context of the current directory so I'll run that and then we very quickly see NPM not found. 69 00:05:00,810 --> 00:05:01,110 All right. 70 00:05:01,140 --> 00:05:03,990 So first problem of a couple that we're going to see. 71 00:05:03,990 --> 00:05:05,660 So let's take a quick pause right here. 72 00:05:05,670 --> 00:05:10,830 We're going to start to investigate why we are seeing this error and fix it up so quick break and I'll 73 00:05:10,830 --> 00:05:11,840 see you in just a minute.