Instructor: In the last section, we made a little change
to our docker file and then tried rebuilding the image.
The good news is that npm is now clearly being
included inside of our container,
and so it's attempting to install dependencies.
However, npm itself very quickly
throughout a error message right here,
complaining that there is no file
called package.json available.
Now, just in case you weren't around,
or you kind of skipped over the section
where we put together the package.json file together,
that is a file inside of our project directory right here.
Its purpose is to list out all the different dependencies
that are required to successfully run our project.
So when we run npm install,
npm is going to try to find this file,
it's gonna find all the dependencies that are listed,
and then it's going to try to install each of those.
So clearly the issue here is
that npm is not finding that file.
So let's talk about why it is.
All right, so quick diagram.
We've looked at this one before.
We've got our container on the right-hand side.
We've got the steps out of our docker file,
and then down here is a little representation
of the node alpine image that we're making use of.
So let's imagine what is going on
inside of our image-building process right now.
First off, we specify node alpine.
That downloads the alpine image,
or excuse me, the node image to be precise.
And then the next step starts up and it says,
"Okay, I'm gonna go back to the previous step
and get the image from there,
and then create a temporary container out of it."
So as soon as run npm install starts to boot up,
we can imagine that we take this file system
snapshot right here.
And we kind of put it into this very temporary container.
And then we execute npm install.
Now, I got a quick question for you.
Do you see anywhere inside of this file system right here?
Do you see a package.json file?
Well, the answer is no.
There is no package.json file available
inside of the container.
The only files and folders that are available
inside the container is exactly whatever came out
of the file system snapshot from the node image.
Remember, we are only working
with a segment of our hard drive inside this container.
There's this entire other rest of the hard drive
kind of like not connected inside this container.
And somewhere inside the rest of the hard drive,
is where our package.json file is.
And that is not at all being communicated
into the container.
And so we do successfully run npm install,
but they're just plain is no package.json file available.
So the takeaway here is that when you are building an image,
none of the files inside of your project directory
right here are available inside the container by default.
They are all a hundred percent sectioned off,
completely segmented out, they are not at all available,
and you cannot assume that any of these files are available
unless you specifically allow it inside of your docker file.
So as my guess, that's exactly what we're going to do.
We're going to add in one line of configuration
to our docker file to make sure that both our index.js file
and package.json file are available inside the container
when we try to run the npm install command.
Let's take a quick pause right here
and then we're going to add in that additional instruction
in the next section.