In last section we saw that the npm install command failed to run because the package not just on file
was not found.
And we spoke about why that was in this section.
We're going to figure out how we can make sure that the package not just on file is available before
npm install is executed inside of the container to do so.
We're going to add one little instruction to our Docker file.
This is going to be an instruction that we've not used before.
It's the copy instruction and as you might guess the copy instruction is used to move files and folders
from our local file system on your machine to the file system inside of that temporary container that
is created during the build process.
The overall syntax for this is copy then a path to the folder on your local file system and then the
path that you want to copy that stuff to inside the container.
Right now I'm showing these commands with a dot slash which means the current working directory.
Now one little technicality here.
The path from our folder the first argument right here is relative to the build context and you'll recall
that I had said that the build context is the dot right here.
When we execute docker build at the terminal.
So build right here means simple web directory or the current working directory.
So we have set the current build context to be simple web.
So then inside the copy command right here.
When I say dot slash that means the build context which is simple web.
I know that's a little bit confusing.
It's essentially kind of like two layers of indirection.
Again we're going to see a better example of why we would alter this build context stuff in the future
when we start working on some more complicated projects right now all we really need to know is that
if we add this right here to our Docker file we're gonna copy everything from our current working directory
into the container and that's pretty much it.
So let's flip over to our darker file and we're gonna add in this instruction and then tried to rebuild
our image.
Now we definitely want to make sure that the package not just on file is available before we run npm
install.
So going to add in the new instruction right above that.
So I'll say copy dot slash dot slash again everything from the current working directory of simple web
to the current working directory inside the container.
All right.
So I'm going to save this and we're going to try to run the docker build command again over at our terminal.
So gonna flip back over and I'll do docker build dot we'll run that now between the last section and
this one I removed my Alpine image or the node Alpine image so I had to re download it but after that
we should see the copy step.
There it is right there.
Well then see npm install.
Now you will notice a couple of little warnings.
The warnings are totally fine.
If you see a notice and then three warnings in a row that's totally fine.
No issue.
So we've now successfully installed all of our NPM dependencies.
And if we keep on scrolling down we'll eventually see at the bottom that we have correctly generated
this new image.
And this is the idea of the new image.
Now remember it's not really nice to work with ideas all the time.
Let's try running the docker build command again but this time we're going to tag the image.
So I'll say Docker builds dash t then my Docker I.D. and then the name of this project which we are
calling simple web.
And then I'm going to make sure that I pass in the build context on the very end.
You'll notice I did not put on the colon latest two the tag right there.
It's because remember the colon latest tag is automatically appended if you don't specify it in here.
Now one thing I just wanna remind you about please don't forget the dot on the very end.
And once you've got that all on there it enter to rebuild it.
And now we have tagged that newly built image as your Docker I.D. slash simple web.
So last thing we're going to do is try to start out that image and get the node server running.
So I'll do a docker run.
Steven Greider slash simple web.
All right.
So I very quickly see that the node index dot J.S. command was issued through the NPM start command.
I then see that the server is correctly listening on port 80 80.
So I think that we're ready to open up a web browser and test this thing out.
So going to flip on over to my browser and to visit that running application we should be able to go
to local host Colin 80 80 but once I do I get a nasty low error message that says this site can't be
reached.
Well we definitely got our image built and we are running a container out of it but we still are not
able to actually visit this port or see the web application running.
So let's take a quick pause right here and we'll continue in the next section and figure out what is
going wrong.