1 00:00:01,100 --> 00:00:04,550 We're now successfully able to visit our running web application site the browser. 2 00:00:04,560 --> 00:00:07,350 But there's one last little thing that I want to point out. 3 00:00:07,530 --> 00:00:10,860 I'm going to start my container up using the image that we've already built. 4 00:00:10,920 --> 00:00:16,020 But this time I'm going to start up a shell inside the container so that we can do a little bit of debugging 5 00:00:16,050 --> 00:00:17,200 inside there. 6 00:00:17,220 --> 00:00:23,970 Remember that we can start up a shell inside of most Alpine based containers by running Docker run dash 7 00:00:24,100 --> 00:00:30,320 I.T. and I'll put down my container name of Steven Greider simple web. 8 00:00:30,900 --> 00:00:35,040 And then I will override the default startup command with sdh. 9 00:00:35,100 --> 00:00:37,650 Remember this is a reference to the shell program. 10 00:00:37,650 --> 00:00:42,390 It will start up a shell that we can type commands into inside the container. 11 00:00:42,390 --> 00:00:45,240 Now you'll notice that I did not specify a port mapping here. 12 00:00:45,290 --> 00:00:47,520 It's because we are not going to actually start up the server. 13 00:00:47,670 --> 00:00:54,090 I just want to attempt to look at the files and folders inside the container so I'll run that and I 14 00:00:54,090 --> 00:00:58,650 will get a command prompt based inside of the root directory of the container. 15 00:00:58,710 --> 00:01:05,490 Now inside of here I'm going to print out all the available files and folders with L S so inside of 16 00:01:05,490 --> 00:01:05,740 here. 17 00:01:05,760 --> 00:01:11,880 You'll notice that when we did that copy operation we copy it into the root directory or the root folder 18 00:01:11,940 --> 00:01:13,140 of the container. 19 00:01:13,170 --> 00:01:18,990 And so in this root directory we can see the darker file a package lock dot Jason File which is automatically 20 00:01:18,990 --> 00:01:25,710 generated by NPM package that Jason indexed J.S. in all of our install dependencies were placed into 21 00:01:25,710 --> 00:01:27,270 this node modules folder. 22 00:01:27,270 --> 00:01:32,820 And again these were all placed into the root directory of this container. 23 00:01:32,820 --> 00:01:35,730 Now this is definitely not the best practice. 24 00:01:35,730 --> 00:01:41,490 And the reason for that is that if we happen to have any files or folders that conflict with a default 25 00:01:41,490 --> 00:01:48,900 folder system like if we have a folder called var or root or run or Lib super super likely for us to 26 00:01:48,900 --> 00:01:53,940 have a folder called live inside of our project we might accidentally overwrite some existing files 27 00:01:53,970 --> 00:01:58,640 or folders inside the container which is definitely not ideal. 28 00:01:58,710 --> 00:02:04,200 So we're gonna make a little change to our Docker file and rather than copying everything directly into 29 00:02:04,200 --> 00:02:10,110 the root project directory we're actually gonna copy everything into kind of a nested directory instead. 30 00:02:10,350 --> 00:02:16,110 Now rather than just changing the copy command inside of our Docker file and saying oh yeah copy it 31 00:02:16,110 --> 00:02:21,600 into like some application folder or something like that there's actually an instruction that we can 32 00:02:21,600 --> 00:02:27,180 use inside the docker file that is specifically meant to address this whole issue right here of accidentally 33 00:02:27,420 --> 00:02:30,610 overwriting files or folders by copying into a root directory. 34 00:02:30,630 --> 00:02:38,700 So let's take a look at what the instruction is so we can add the work dir or work directory instruction 35 00:02:38,730 --> 00:02:46,770 into the docker file and then pass a reference to a folder to it then any following commands or any 36 00:02:46,830 --> 00:02:52,970 following instructions so we add to our Docker file we'll be executed relative to this folder. 37 00:02:53,040 --> 00:02:59,520 So in other words if we add the work dir and then a folder above the copy instruction right here it 38 00:02:59,520 --> 00:03:04,620 will make sure that we only execute or Sammy it'll make sure that when we actually do the copy instruction 39 00:03:04,800 --> 00:03:06,440 it won't copy it into the work directory. 40 00:03:06,440 --> 00:03:07,470 I mean the root directory. 41 00:03:07,590 --> 00:03:12,710 It'll copy it into the directory that we have specified as the working directory instead. 42 00:03:12,750 --> 00:03:14,920 So let's try doing that right now. 43 00:03:15,050 --> 00:03:21,690 I'm going to add in an instruction of work dir and then we're going to use a folder of slash user slash 44 00:03:21,750 --> 00:03:22,300 app. 45 00:03:22,530 --> 00:03:28,920 So say slash user slash app if this folder does not exist inside the container it'll be automatically 46 00:03:28,920 --> 00:03:30,140 created for us. 47 00:03:30,150 --> 00:03:33,700 Now you might be curious as to why I'm using it user slash app. 48 00:03:33,810 --> 00:03:40,260 Well to be honest in the No GST world it doesn't make a tremendous difference where you put your application 49 00:03:40,290 --> 00:03:42,800 into in a Linux based operating system. 50 00:03:42,810 --> 00:03:47,400 There definitely are places you don't want to put it but at the end of the day the user folder is a 51 00:03:47,400 --> 00:03:54,060 safe place to put your application it's specified as the location for all of user home directories. 52 00:03:54,060 --> 00:03:57,260 Essentially it's an okay place for us to put our application. 53 00:03:57,300 --> 00:04:01,830 Now as I say that there's definitely a lot of Linux diehards out there who would probably disagree with 54 00:04:01,830 --> 00:04:06,660 me and they might say oh no you should put this in to var or you should put it into the home directory 55 00:04:06,660 --> 00:04:07,330 instead. 56 00:04:07,350 --> 00:04:11,160 So there is some disagreement out there on where the best place is for your application. 57 00:04:11,190 --> 00:04:16,310 I can just about guarantee you that if you put it into user slash app you're probably going to be OK. 58 00:04:18,020 --> 00:04:18,280 OK. 59 00:04:18,320 --> 00:04:21,020 So now we've added into the worked our instruction. 60 00:04:21,020 --> 00:04:25,850 I'm not going to save the docker file and then we'll flip back over to our terminal I'll exit the running 61 00:04:25,850 --> 00:04:32,060 container by typing in exit and then we're going to make sure that we first rebuild our container and 62 00:04:32,060 --> 00:04:34,250 then we will try to relaunch it. 63 00:04:34,340 --> 00:04:38,820 So I'll do a rebuild with docker build dot. 64 00:04:38,890 --> 00:04:47,040 Now let's not forget to tag it so docker build dash t your Docker ideas slash simple web and then a 65 00:04:47,040 --> 00:04:47,580 dot. 66 00:04:47,600 --> 00:04:48,500 There we go. 67 00:04:49,860 --> 00:04:51,340 So we're going to rebuild it. 68 00:04:51,360 --> 00:04:56,970 Now one thing that you'll notice is really interesting because we made a change to an instruction above 69 00:04:57,030 --> 00:05:02,670 the copy and npm install everything after that instruction has to rerun from scratch. 70 00:05:02,730 --> 00:05:04,910 So we cannot use any cash versions. 71 00:05:05,130 --> 00:05:10,230 In other words the npm install command has to run again and reinstall all of our dependencies because 72 00:05:10,230 --> 00:05:16,510 we can not use the Cash version of that step so we got our output here. 73 00:05:16,510 --> 00:05:18,730 Let's try starting up our container again. 74 00:05:18,880 --> 00:05:23,020 First started up in normal mode and try to visit inside my browser. 75 00:05:23,020 --> 00:05:32,200 So we'll do a docker run DSP to set up a port mapping and we'll map 80 80 to 80 80 and then the container 76 00:05:32,200 --> 00:05:36,070 that I want to run is steam Greider slash simple web 77 00:05:39,270 --> 00:05:43,480 so we'll run that and then I'll go back over in my browser. 78 00:05:43,890 --> 00:05:50,180 I'll try to visit local host 80 80 and yet it looks like we're good to go. 79 00:05:50,190 --> 00:05:56,040 I can refresh the page and if we also try to start up a shell inside the container we'll see that all 80 00:05:56,040 --> 00:06:00,150 of our project directories or something all of our project files are no longer in the root directory 81 00:06:00,630 --> 00:06:07,650 to do so we can either rerun the docker run command with the I.T. and SDH attached to it or we can use 82 00:06:07,650 --> 00:06:09,590 that Docker exact command. 83 00:06:09,630 --> 00:06:14,820 You recall we can use Docker exact to start up a second process inside of a running container. 84 00:06:14,820 --> 00:06:18,490 Let's try doing it that way just for a little bit of variety. 85 00:06:18,660 --> 00:06:21,680 So I will open up a second terminal window. 86 00:06:21,870 --> 00:06:25,360 I'll get the idea that running container by using Docker. 87 00:06:25,400 --> 00:06:25,920 Yes. 88 00:06:26,460 --> 00:06:31,740 So here's the idea right here and then we can attach to that container and start up a shell inside of 89 00:06:31,740 --> 00:06:39,180 it by using Docker exactly dash I.T. the I.D. of the container and then the program that we want to 90 00:06:39,180 --> 00:06:41,940 run inside of it which in this case is Shell. 91 00:06:42,030 --> 00:06:47,640 Don't forget the I.T. right here is to attach standard in and a nice looking terminal to the shell that 92 00:06:47,640 --> 00:06:48,150 starts up. 93 00:06:49,440 --> 00:06:55,420 So I'll run that and you'll notice that we enter directly in to the user slash app folder because we 94 00:06:55,420 --> 00:07:00,270 had setup that working directory previously that worked our instruction right here. 95 00:07:00,360 --> 00:07:06,210 Not only affects commands that are issued later on INSIDE OF OUR Docker file it also affects commands 96 00:07:06,390 --> 00:07:13,780 that are executed inside the container later on through the docker exact command so if I now do an LSD 97 00:07:13,790 --> 00:07:19,700 right here I'll see all of my project files and folders nicely isolated inside of this single file and 98 00:07:19,700 --> 00:07:25,700 I can change back to my root directory by doing CDE forward slash printout all the files and folders 99 00:07:25,700 --> 00:07:30,590 there with Elvis and I'll see that I do not have any possible conflicts going on. 100 00:07:30,590 --> 00:07:37,170 We have nicely spaced out application or kind of isolated our application into this folder right here. 101 00:07:37,250 --> 00:07:37,600 All right. 102 00:07:37,640 --> 00:07:43,700 That's very much it looking pretty good now believe it or not there is one last little thing that I 103 00:07:43,700 --> 00:07:44,530 want to look at. 104 00:07:44,540 --> 00:07:50,150 So let's do one more quick break and we'll come back in the next section and do one quick quick last 105 00:07:50,150 --> 00:07:50,630 little thing. 106 00:07:50,660 --> 00:07:51,700 So I'll see you in just a minute.