1 00:00:00,960 --> 00:00:06,090 In last section we saw that the npm install command failed to run because the package not just on file 2 00:00:06,090 --> 00:00:06,810 was not found. 3 00:00:06,840 --> 00:00:09,320 And we spoke about why that was in this section. 4 00:00:09,330 --> 00:00:13,770 We're going to figure out how we can make sure that the package not just on file is available before 5 00:00:13,770 --> 00:00:18,090 npm install is executed inside of the container to do so. 6 00:00:18,090 --> 00:00:22,270 We're going to add one little instruction to our Docker file. 7 00:00:22,380 --> 00:00:24,690 This is going to be an instruction that we've not used before. 8 00:00:24,690 --> 00:00:30,330 It's the copy instruction and as you might guess the copy instruction is used to move files and folders 9 00:00:30,540 --> 00:00:36,300 from our local file system on your machine to the file system inside of that temporary container that 10 00:00:36,300 --> 00:00:38,640 is created during the build process. 11 00:00:38,640 --> 00:00:45,930 The overall syntax for this is copy then a path to the folder on your local file system and then the 12 00:00:45,930 --> 00:00:49,780 path that you want to copy that stuff to inside the container. 13 00:00:49,800 --> 00:00:55,380 Right now I'm showing these commands with a dot slash which means the current working directory. 14 00:00:55,440 --> 00:00:57,050 Now one little technicality here. 15 00:00:57,150 --> 00:01:03,900 The path from our folder the first argument right here is relative to the build context and you'll recall 16 00:01:03,900 --> 00:01:07,610 that I had said that the build context is the dot right here. 17 00:01:08,040 --> 00:01:10,380 When we execute docker build at the terminal. 18 00:01:10,380 --> 00:01:15,020 So build right here means simple web directory or the current working directory. 19 00:01:15,060 --> 00:01:18,850 So we have set the current build context to be simple web. 20 00:01:19,200 --> 00:01:21,260 So then inside the copy command right here. 21 00:01:21,270 --> 00:01:25,720 When I say dot slash that means the build context which is simple web. 22 00:01:26,250 --> 00:01:27,570 I know that's a little bit confusing. 23 00:01:27,570 --> 00:01:30,390 It's essentially kind of like two layers of indirection. 24 00:01:30,420 --> 00:01:34,950 Again we're going to see a better example of why we would alter this build context stuff in the future 25 00:01:35,160 --> 00:01:39,720 when we start working on some more complicated projects right now all we really need to know is that 26 00:01:39,720 --> 00:01:45,690 if we add this right here to our Docker file we're gonna copy everything from our current working directory 27 00:01:45,900 --> 00:01:48,640 into the container and that's pretty much it. 28 00:01:48,660 --> 00:01:53,400 So let's flip over to our darker file and we're gonna add in this instruction and then tried to rebuild 29 00:01:53,430 --> 00:01:55,750 our image. 30 00:01:56,150 --> 00:02:01,690 Now we definitely want to make sure that the package not just on file is available before we run npm 31 00:02:01,690 --> 00:02:02,490 install. 32 00:02:02,510 --> 00:02:05,140 So going to add in the new instruction right above that. 33 00:02:05,920 --> 00:02:13,600 So I'll say copy dot slash dot slash again everything from the current working directory of simple web 34 00:02:13,990 --> 00:02:18,370 to the current working directory inside the container. 35 00:02:18,430 --> 00:02:18,730 All right. 36 00:02:18,760 --> 00:02:24,510 So I'm going to save this and we're going to try to run the docker build command again over at our terminal. 37 00:02:25,570 --> 00:02:33,970 So gonna flip back over and I'll do docker build dot we'll run that now between the last section and 38 00:02:33,970 --> 00:02:39,160 this one I removed my Alpine image or the node Alpine image so I had to re download it but after that 39 00:02:39,190 --> 00:02:40,750 we should see the copy step. 40 00:02:40,810 --> 00:02:41,920 There it is right there. 41 00:02:41,920 --> 00:02:43,780 Well then see npm install. 42 00:02:43,780 --> 00:02:45,950 Now you will notice a couple of little warnings. 43 00:02:45,970 --> 00:02:47,530 The warnings are totally fine. 44 00:02:47,620 --> 00:02:51,370 If you see a notice and then three warnings in a row that's totally fine. 45 00:02:51,370 --> 00:02:52,460 No issue. 46 00:02:52,570 --> 00:02:56,300 So we've now successfully installed all of our NPM dependencies. 47 00:02:56,440 --> 00:03:01,030 And if we keep on scrolling down we'll eventually see at the bottom that we have correctly generated 48 00:03:01,090 --> 00:03:02,200 this new image. 49 00:03:02,200 --> 00:03:04,670 And this is the idea of the new image. 50 00:03:04,690 --> 00:03:08,250 Now remember it's not really nice to work with ideas all the time. 51 00:03:08,260 --> 00:03:13,600 Let's try running the docker build command again but this time we're going to tag the image. 52 00:03:13,750 --> 00:03:21,910 So I'll say Docker builds dash t then my Docker I.D. and then the name of this project which we are 53 00:03:21,910 --> 00:03:23,110 calling simple web. 54 00:03:23,980 --> 00:03:28,030 And then I'm going to make sure that I pass in the build context on the very end. 55 00:03:28,390 --> 00:03:31,690 You'll notice I did not put on the colon latest two the tag right there. 56 00:03:31,720 --> 00:03:39,040 It's because remember the colon latest tag is automatically appended if you don't specify it in here. 57 00:03:39,040 --> 00:03:42,910 Now one thing I just wanna remind you about please don't forget the dot on the very end. 58 00:03:43,000 --> 00:03:46,600 And once you've got that all on there it enter to rebuild it. 59 00:03:46,600 --> 00:03:51,450 And now we have tagged that newly built image as your Docker I.D. slash simple web. 60 00:03:51,910 --> 00:03:57,580 So last thing we're going to do is try to start out that image and get the node server running. 61 00:03:57,580 --> 00:03:59,380 So I'll do a docker run. 62 00:03:59,410 --> 00:04:05,290 Steven Greider slash simple web. 63 00:04:05,660 --> 00:04:05,970 All right. 64 00:04:05,970 --> 00:04:12,240 So I very quickly see that the node index dot J.S. command was issued through the NPM start command. 65 00:04:12,240 --> 00:04:15,880 I then see that the server is correctly listening on port 80 80. 66 00:04:15,900 --> 00:04:19,950 So I think that we're ready to open up a web browser and test this thing out. 67 00:04:19,980 --> 00:04:24,930 So going to flip on over to my browser and to visit that running application we should be able to go 68 00:04:24,930 --> 00:04:34,970 to local host Colin 80 80 but once I do I get a nasty low error message that says this site can't be 69 00:04:34,970 --> 00:04:35,990 reached. 70 00:04:35,990 --> 00:04:41,210 Well we definitely got our image built and we are running a container out of it but we still are not 71 00:04:41,210 --> 00:04:45,490 able to actually visit this port or see the web application running. 72 00:04:45,500 --> 00:04:49,400 So let's take a quick pause right here and we'll continue in the next section and figure out what is 73 00:04:49,400 --> 00:04:49,900 going wrong.