Now in the vast majority of use cases,
you don't just want to download and run an image
that gives you an interactive shell
like the node image does at the moment.
This is nice to get started
and to have our first experience with containers and images,
but it's not all we wanna do.
Instead, typically you build up on those space images
to then build your own images.
Like for example here,
we could build up on the node image
to then execute certain node JS code with that image.
And of course, node is just one example here.
An example I will use a lot throughout the course,
but the same would be true for PHP,
for GO, for Python,
whichever programming language you're using,
whichever application you might be building.
Typically you would pull into your official base image
and then add your code on top of that
to execute your code with that image.
And of course you wanna do all of that
inside of a container.
And that is a scenario where you need to build
your own image because your exact application
with your code.
Of course, this does not exist on Docker hub
unless you shared it dear.
So therefore, now we'll build our own image
building up on this node image though,
and for that I prepared a very simple node JS dummy project
and you don't need to know node to follow along.
You can simply download this dummy project.
You find it attached and it contains four files here,
a server JS file,
which contains our main node application code.
In case you know node,
you can quickly see what this does
In case you don't know it,
this starts a web server with node JS,
listening on port 80
and we handle incoming requests to two URLs
to our domain slash nothing
if it's a get HTTP request,
in which case this HTML code will be returned.
And we handle post requests to store a goal
where we then try to retrieve a goal key,
a goal value from the incoming request body.
We then lock this goal to the console
and we set some user goal variable equal
to that extracted goal.
And then we redirect to the slash route again
so to this route
and here we then render HTML code
where we utilize this user goal variable,
which has a default value,
which is eventually overwritten to the entered goal value.
And this variable is output here.
This is Java script code executed with node
to bring up such a node web server.
But again, you don't need to know node.
This course is not about node.
This is just one example application
which you wanna dockerize,
which we wanna run in a Docker container.
Now, two other key things belong to this application.
One key thing is the public folder,
which has a CSS file for some styling.
This file is automatically loaded in the end
by telling the node server
to well, just redirect requests to files
to the public folder
and then look for such files there,
which is why I request two styles.
CSS will load style CSS, which is in the public folder,
but then probably the more important
our key thing we have here
is the package.json file.
Here, we describe this node application
and that is a node exclusive concept.
It has nothing to do with Docker,
this package.json file.
But here we tell node
which dependencies we have,
which other third party packages
we need to run this node application
in this case that's the express framework
which is a node JS package
we can use in our node JS applications
and the body parser package.
Now, if you would want to run this project locally
without Docker, you would need to install Node JS
from nodejs.org.
For example, that latest version
and then thereafter in your project folder
in a terminal opened in that folder.
And here, this is my default terminal
just integrated in visual studio code,
the idea I'm using here,
automatically navigated into this project folder.
And in this terminal, you would need to run NPM install.
NPM is another tool shipping together
with node JS,
so being installed automatically
when you install Node
and NPM install will now download
and install all the dependencies we need.
And then thereafter, once you did this,
you could execute the server JS file with the node command.
And this would then start the server
and on local host, port 80,
you could visit this application, set your goal
and see this in action.
Now this is the node application running locally
without Docker and you don't need to install Node.
This was just an example how we would run it without Docker.
Now, of course, this course is about Docker though.
So let's quit this with Ctrl + C.
Let's clear this console
and let's actually delete the node
modules folder
which was created after running NPM install.
And let's all deletes,
the package dash lock json file here.
So that we're back to the initial files.
The get ignore file, by the way is optional.
It's just important if you're using
get for version control.
So this is now a node application.
How can we now build our own image
that contains this application
and that then also utilizes the node Docker hub image
to run that code?