1 00:00:04,200 --> 00:00:10,140 ‫All right. These are the answers for the assignment of creating our first Dockerfile. If I'm in the root of our 2 00:00:10,140 --> 00:00:14,990 ‫repository, that you downloaded from the beginning of this course, 3 00:00:15,030 --> 00:00:23,470 ‫we should be able to go into dockerfile assignment 1. If we look in there, 4 00:00:23,580 --> 00:00:28,640 ‫I've only got one file that I really care about, and that's the Dockerfile. 5 00:00:28,670 --> 00:00:36,710 ‫Presumably, this is a source that somebody gave to me, and they're an app dev that is using Node.js, and I 6 00:00:36,710 --> 00:00:41,020 ‫don't really know a lot about it, so I'm just going to edit the Dockerfile. 7 00:00:42,470 --> 00:00:42,920 ‫OK. 8 00:00:42,920 --> 00:00:48,260 ‫If I follow the instructions from the developer, I know the first thing I need to do is I need to 9 00:00:48,260 --> 00:00:57,000 ‫go get my FROM image. And I know I need to use the node official. Let me go look it up. 10 00:01:06,010 --> 00:01:07,500 ‫Right. There's the node official. 11 00:01:11,490 --> 00:01:19,540 ‫I need Version 6 running on Alpine. So there's 6 Alpine. 12 00:01:19,750 --> 00:01:22,100 ‫All right. So, 6-alpine. 13 00:01:26,230 --> 00:01:36,050 ‫Ok. The next thing...I need to expose port 3000. 14 00:01:36,760 --> 00:01:40,250 ‫I'm exposing 3000 here because that's what the app is designed to run on. 15 00:01:40,250 --> 00:01:45,410 ‫But when I run it later with docker run, I need to remember that I'm going to have to use the -p 16 00:01:45,410 --> 00:01:49,030 ‫with port 80 going to port 3000. 17 00:01:49,260 --> 00:01:50,340 ‫All right. 18 00:01:50,380 --> 00:01:54,710 ‫This one needs to use a package manager to install 19 00:01:57,020 --> 00:02:02,140 ‫this app, tini. I'll use a run command for that. 20 00:02:05,440 --> 00:02:09,660 ‫Then I'm going to make a directory. 21 00:02:10,080 --> 00:02:10,440 ‫All right. 22 00:02:10,450 --> 00:02:15,490 ‫I'll just make them separate run commands...run apk add, 23 00:02:18,660 --> 00:02:21,700 ‫and then run mkdir. 24 00:02:24,460 --> 00:02:29,260 ‫OK. Then I need to copy in a single file it looks like. 25 00:02:29,490 --> 00:02:34,090 ‫So, I might as well change the working directory to that directory we just created. 26 00:02:34,090 --> 00:02:40,750 ‫So WORKDIR user source app. That'll save me time later. 27 00:02:41,010 --> 00:02:47,010 ‫I can do a COPY package json 28 00:02:48,190 --> 00:02:58,360 ‫package json. All right. Then I need to run an install command. It looks like it'll be a run. This one says run another 29 00:02:58,360 --> 00:03:00,110 ‫command to clean up. 30 00:03:00,130 --> 00:03:00,360 ‫All right. 31 00:03:00,370 --> 00:03:06,610 ‫Well, usually when you run a cleanup command, you want it to run the same line or the same run line as 32 00:03:06,880 --> 00:03:07,720 ‫the actual install. 33 00:03:07,720 --> 00:03:12,550 ‫That way it removes everything all at the same time and you only get one image layer. 34 00:03:12,580 --> 00:03:15,460 ‫This is best for image space. 35 00:03:15,490 --> 00:03:18,420 ‫So, I'm going to add it here. 36 00:03:19,230 --> 00:03:25,180 ‫And what the double & sign, or the ampersand as it's called, does here is it actually is a conditional. 37 00:03:25,180 --> 00:03:31,360 ‫It says to the command line on Linux that says, 'Hey, if you've done the first one and it's successful, 38 00:03:31,420 --> 00:03:33,170 ‫then do the second command.' 39 00:03:33,640 --> 00:03:39,910 ‫You might also see people sometimes putting in a semicolon, and that's fine too. 40 00:03:39,910 --> 00:03:44,260 ‫The difference is a semicolon doesn't have a dependency on whether or not the first command was successful. 41 00:03:44,260 --> 00:03:46,580 ‫It just runs the second one regardless. 42 00:03:47,050 --> 00:03:50,060 ‫So I like the double ampersand. 43 00:03:50,110 --> 00:03:50,410 ‫All right. 44 00:03:50,630 --> 00:03:54,910 ‫Copying some more files it looks like. If I'm going to copy in everything, I'll just do a .. . 45 00:03:54,940 --> 00:03:56,490 ‫That's an easy way to do it. 46 00:03:56,500 --> 00:03:57,680 ‫Make sure there's a space in the middle. 47 00:03:57,700 --> 00:04:03,280 ‫That's basically saying, 'Copy everything from my current directory on the host to the current working 48 00:04:03,280 --> 00:04:05,250 ‫directory in the image.' 49 00:04:05,260 --> 00:04:05,860 ‫OK. 50 00:04:05,910 --> 00:04:08,100 ‫I'm down to the last one. 51 00:04:10,020 --> 00:04:12,810 ‫And this one looks a little tricky. 52 00:04:12,810 --> 00:04:16,870 ‫I've got four different parts of the command I need to run there. 53 00:04:16,890 --> 00:04:23,820 ‫So with this format, I need to run tini, then a comma. 54 00:04:23,820 --> 00:04:25,480 ‫So this is in a JSON format. 55 00:04:25,500 --> 00:04:34,540 ‫This particular command stanza. --, node bin www. 56 00:04:34,930 --> 00:04:42,900 ‫And if I was curious about that, I could always go over to my browser and do docker run or docker build 57 00:04:42,910 --> 00:04:43,730 ‫cmd. 58 00:04:43,740 --> 00:04:48,390 ‫And I bet you Dockerfile reference. And here on this page, 59 00:04:48,390 --> 00:04:56,910 ‫I could go to the cmd. And it talks about the exact form. If you read here, you'll actually notice 60 00:04:56,910 --> 00:05:01,080 ‫that there is something called a shell form. And there's also something they're mentioning about an entry 61 00:05:01,080 --> 00:05:01,750 ‫point. 62 00:05:01,770 --> 00:05:05,710 ‫We're going to talk about that later in the course in a more advanced Dockerfile section. 63 00:05:05,910 --> 00:05:07,180 ‫But for now, this is good. 64 00:05:07,590 --> 00:05:13,200 ‫Let's try to build it. docker build. I don't really care what I call it right now. 65 00:05:13,200 --> 00:05:18,360 ‫I'm just trying to test the build and usually my builds don't work the first time. So, I'm just going to 66 00:05:18,360 --> 00:05:22,680 ‫call it testnode. I'm going to build this directory. 67 00:05:28,820 --> 00:05:29,240 ‫OK. 68 00:05:29,250 --> 00:05:30,560 ‫It's looks like it built correctly. 69 00:05:30,810 --> 00:05:31,920 ‫Let's see if you can run it. 70 00:05:35,840 --> 00:05:38,980 ‫I'm going to do a --rm because I really don't care to keep it 71 00:05:39,030 --> 00:05:42,020 ‫after I've tested it, so I'm just going to do that. 72 00:05:42,030 --> 00:05:43,880 ‫I'm not going to need to name it. 73 00:05:46,380 --> 00:05:55,240 ‫I need to put in a port to open the port. It wants to run on 80 but it listens on 3000. OK. 74 00:05:55,580 --> 00:06:00,650 ‫That's actually a normal message that we get from tini, inside of Alpine, so I won't worry about 75 00:06:00,650 --> 00:06:01,310 ‫that too much. 76 00:06:01,310 --> 00:06:03,350 ‫Let's go see if it works. 77 00:06:06,440 --> 00:06:09,090 ‫Sweet. We'll see the logs there. 78 00:06:09,350 --> 00:06:09,790 ‫OK. 79 00:06:09,810 --> 00:06:10,460 ‫Looks like it's.. 80 00:06:10,550 --> 00:06:11,810 ‫thank you, Captain Picard. 81 00:06:11,840 --> 00:06:12,950 ‫I appreciate the applause. 82 00:06:12,950 --> 00:06:13,850 ‫I appreciate the support. 83 00:06:13,850 --> 00:06:15,800 ‫Thanks. 84 00:06:15,800 --> 00:06:17,190 ‫All right. 85 00:06:17,490 --> 00:06:21,770 ‫Control c out of there. Now, 86 00:06:22,080 --> 00:06:24,510 ‫it should be at the top of my images list. 87 00:06:24,840 --> 00:06:27,780 ‫I need to rename it before I put it on Docker Hub. 88 00:06:28,290 --> 00:06:36,720 ‫So, docker tag, and I believe the format is the old and the new. Yeah. 89 00:06:36,820 --> 00:06:40,000 ‫So, docker tag testnode. 90 00:06:40,200 --> 00:06:44,260 ‫I'm going to call it bretfisher 91 00:06:46,780 --> 00:06:49,560 ‫testing node. 92 00:06:49,790 --> 00:06:51,900 ‫And I'll just leave it at latest. 93 00:06:51,910 --> 00:07:01,830 ‫So, docker push, and this. All we need to worry about is the name. So, docker push 94 00:07:02,090 --> 00:07:07,920 ‫bretfisher testing node. 95 00:07:07,960 --> 00:07:10,400 ‫All right. Let's go over to Docker and look. 96 00:07:13,420 --> 00:07:15,140 ‫There we go, testing node. 97 00:07:15,460 --> 00:07:16,470 ‫OK. 98 00:07:17,180 --> 00:07:22,320 ‫I'm going to clear the screen and docker image ls. 99 00:07:22,380 --> 00:07:26,210 ‫And, it's there. I'm going to remove it, 100 00:07:26,250 --> 00:07:31,970 ‫docker image rm bretfisher testing. 101 00:07:31,990 --> 00:07:36,600 ‫All right. Now I'm actually going to run it, docker container run 102 00:07:36,610 --> 00:07:42,660 ‫--rm -p 80 3000 just like before. 103 00:07:42,700 --> 00:07:46,670 ‫Then I'm actually going to call it bretfisher testing node. 104 00:07:47,290 --> 00:07:51,570 ‫That should download it and run it. 105 00:07:51,650 --> 00:07:52,210 ‫All right. 106 00:07:52,220 --> 00:07:59,920 ‫If I go back over my browser, localhost, there it is. I can hit refresh just to make sure. 107 00:08:00,220 --> 00:08:01,270 ‫Yes. Cool.