‫All right. These are the answers for the assignment of creating our first Dockerfile. If I'm in the root of our
‫repository, that you downloaded from the beginning of this course,
‫we should be able to go into dockerfile assignment 1. If we look in there,
‫I've only got one file that I really care about, and that's the Dockerfile.
‫Presumably, this is a source that somebody gave to me, and they're an app dev that is using Node.js, and I
‫don't really know a lot about it, so I'm just going to edit the Dockerfile.
‫OK.
‫If I follow the instructions from the developer, I know the first thing I need to do is I need to
‫go get my FROM image. And I know I need to use the node official. Let me go look it up.
‫Right. There's the node official.
‫I need Version 6 running on Alpine. So there's 6 Alpine.
‫All right. So, 6-alpine.
‫Ok. The next thing...I need to expose port 3000.
‫I'm exposing 3000 here because that's what the app is designed to run on.
‫But when I run it later with docker run, I need to remember that I'm going to have to use the -p
‫with port 80 going to port 3000.
‫All right.
‫This one needs to use a package manager to install
‫this app, tini. I'll use a run command for that.
‫Then I'm going to make a directory.
‫All right.
‫I'll just make them separate run commands...run apk add,
‫and then run mkdir.
‫OK. Then I need to copy in a single file it looks like.
‫So, I might as well change the working directory to that directory we just created.
‫So WORKDIR user source app. That'll save me time later.
‫I can do a COPY package json
‫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
‫command to clean up.
‫All right.
‫Well, usually when you run a cleanup command, you want it to run the same line or the same run line as
‫the actual install.
‫That way it removes everything all at the same time and you only get one image layer.
‫This is best for image space.
‫So, I'm going to add it here.
‫And what the double & sign, or the ampersand as it's called, does here is it actually is a conditional.
‫It says to the command line on Linux that says, 'Hey, if you've done the first one and it's successful,
‫then do the second command.'
‫You might also see people sometimes putting in a semicolon, and that's fine too.
‫The difference is a semicolon doesn't have a dependency on whether or not the first command was successful.
‫It just runs the second one regardless.
‫So I like the double ampersand.
‫All right.
‫Copying some more files it looks like. If I'm going to copy in everything, I'll just do a .. .
‫That's an easy way to do it.
‫Make sure there's a space in the middle.
‫That's basically saying, 'Copy everything from my current directory on the host to the current working
‫directory in the image.'
‫OK.
‫I'm down to the last one.
‫And this one looks a little tricky.
‫I've got four different parts of the command I need to run there.
‫So with this format, I need to run tini, then a comma.
‫So this is in a JSON format.
‫This particular command stanza. --, node bin www.
‫And if I was curious about that, I could always go over to my browser and do docker run or docker build
‫cmd.
‫And I bet you Dockerfile reference. And here on this page,
‫I could go to the cmd. And it talks about the exact form. If you read here, you'll actually notice
‫that there is something called a shell form. And there's also something they're mentioning about an entry
‫point.
‫We're going to talk about that later in the course in a more advanced Dockerfile section.
‫But for now, this is good.
‫Let's try to build it. docker build. I don't really care what I call it right now.
‫I'm just trying to test the build and usually my builds don't work the first time. So, I'm just going to
‫call it testnode. I'm going to build this directory.
‫OK.
‫It's looks like it built correctly.
‫Let's see if you can run it.
‫I'm going to do a --rm because I really don't care to keep it
‫after I've tested it, so I'm just going to do that.
‫I'm not going to need to name it.
‫I need to put in a port to open the port. It wants to run on 80 but it listens on 3000. OK.
‫That's actually a normal message that we get from tini, inside of Alpine, so I won't worry about
‫that too much.
‫Let's go see if it works.
‫Sweet. We'll see the logs there.
‫OK.
‫Looks like it's..
‫thank you, Captain Picard.
‫I appreciate the applause.
‫I appreciate the support.
‫Thanks.
‫All right.
‫Control c out of there. Now,
‫it should be at the top of my images list.
‫I need to rename it before I put it on Docker Hub.
‫So, docker tag, and I believe the format is the old and the new. Yeah.
‫So, docker tag testnode.
‫I'm going to call it bretfisher
‫testing node.
‫And I'll just leave it at latest.
‫So, docker push, and this. All we need to worry about is the name. So, docker push
‫bretfisher testing node.
‫All right. Let's go over to Docker and look.
‫There we go, testing node.
‫OK.
‫I'm going to clear the screen and docker image ls.
‫And, it's there. I'm going to remove it,
‫docker image rm bretfisher testing.
‫All right. Now I'm actually going to run it, docker container run
‫--rm -p 80 3000 just like before.
‫Then I'm actually going to call it bretfisher testing node.
‫That should download it and run it.
‫All right.
‫If I go back over my browser, localhost, there it is. I can hit refresh just to make sure.
‫Yes. Cool.