In last section we put together the core of the no Jesus web application.
If you didn't follow along the last section and you just copy pasted the code just make sure that you've
got your index out today as file in a package not just on file.
You'll also want to make sure that you've got your terminal open inside of your project directory.
And so if I list out my current files and folders I should see the indexed dot Jesus and package such
a sum files.
OK so we've got some source code here and now we need to figure out how we can wrap this all up inside
of a docker container.
I want to first begin by telling you a little bit about know James and how we're going to start up this
application.
So just in case you've never made use of note before two commands that you need to be aware of to install
dependencies in start up this application.
Anytime that we want to start up a node app we have to first install a set of dependencies and we can
install all of our dependencies by running a command npm install inside of our project directory.
This starts up a little program called NPM which is somewhat called colloquially known as the node package
manager.
This is going to run that program and install a couple of dependencies for us.
And of course it assumes that NPM is installed on our local machine we're inside the container as the
case may be.
The other thing to be aware of is that we're going to have to eventually start our server up and to
do so we're going to run the command NPM start at the terminal as well.
And again this also kind of assumes that NPM is already installed.
All right.
So with all this in mind let's now start thinking about the docker file that we have to put together.
Now this series of operations that we are going to put into the docker file is going to end up looking
very similar to what we did in the last application.
So in this somewhat complicated diagram our template that we're kind of following here for our Docker
file is to specify a base image run some command to install some dependencies which definitely sounds
like something we have to do and then specify the command to run on startup which as we just discussed
is that NPM start thing now over when we are working on the reddest image we said from alpine to specify
the base image we ran a B.K. at readies to install the dependency and then we set up the default command
as red as server.
And so it really seems like we have some very direct parallels this time around.
I think that for the node application we could probably do a docker file that specifies Alpine as our
base image.
We can then run npm install to install all of our dependencies and then we can setup the default command
of NPM start to run the server when the container first comes online.
So we're going to take this type of approach right here by creating a doctor file and then essentially
putting almost exactly these instructions inside of it.
Now quick disclaimer just a quick disclaimer here.
Remember I had said we're going to do a few things here slightly wrong just so you can see some very
common error messages that you are just about guaranteed to see on your own personal projects.
So maybe in this discussion or the series of steps I just described there might be something in here
that doesn't quite line up with what's reality or what we really have to do.
OK all right.
So let's get started.
I'm going to begin by making sure I've got my code Ed open.
Based on that simple web directory and inside of here I'm going to make a new Docker file.
Remember it's darker with a capital D and there is no file extension on there than inside of here.
We're going to first specify our base image and just to be really complete.
I'm going to add in some comments for these steps.
Just to remind you what we're doing every step along the way.
So I'll say specify a base image and you know what.
Let's use that alpine image again it really seemed like it worked out last time for us.
Next up we're going to install some dependencies to do so we will run the command npm install like I
just said the NPM installed command is how we installed dependencies on a node J.S. Project and then
finally we will set up a default command which we can do by running out CMT and then we put down a set
of square brackets and then in a set of double quotes we separately list out all the parts of the command
that we want to run.
When the container is first created and so to start up our server we are probably going to want NPM
start like so.
Notice that I've got a comma between those two strings all right.
I think this looks pretty good.
It definitely looks very similar to what we did for reds.
So let's now flip back over to our terminal and see what happens when we try to build this image.
So I'm going to list out my files and folders and verify that I now see the docker file inside of here.
And then remember to build an image we can run docker build and then we put the dot in there to specify
the build context of the current directory so I'll run that and then we very quickly see NPM not found.
All right.
So first problem of a couple that we're going to see.
So let's take a quick pause right here.
We're going to start to investigate why we are seeing this error and fix it up so quick break and I'll
see you in just a minute.