-: We've now finished up our first little application
using Docker.
We're now gonna start working on our second application,
which is gonna be a little bit more complicated in nature
and it's going to require us to learn
some more advanced features around Docker.
Let's first take a look at a mock-up
of what we're going to build.
All right, so here it is.
This is really a classic example of Docker in action.
You're gonna find a lot of other applications out there
that are very similar in nature.
So the purpose of this tiny little application
is to make a Docker container that contains
a web application that simply displays inside the browser
the number of times that someone essentially
has visited this server.
And so you can see right now it says,
"Number of visits, 10," that indicates that this page
has been visited 10 times.
Now, in order to build this,
we're gonna need two separate components.
First off, we're gonna need some type of web server,
something to actually respond to HTTP requests
and generate some HTML to show inside the browser.
To actually store the number of times
that this thing has been visited,
we're going to also make use of a little Redis server.
Remember, Redis is an in-memory data store.
You can essentially think of it as a tiny little database
that sits entirely inside of memory.
The only purpose of the Redis server is going to be
to contain the number of times
that the page has been visited.
Now, something to be aware of here,
yes, we absolutely could store this number of visits
inside the Node application itself.
That's totally an option.
However, just to make this thing a little bit more,
kind of, sufficiently complicated,
we are going to be making use of Redis.
Now, I wanna think a little bit
about how we're going to generally architecture
this app using Docker.
And your first impression here, maybe your first guess,
might be that we're going to make a single container
and inside that single container
we could run both our Node application and a Redis server.
Now, don't get me wrong, this is totally possible,
you could take this approach right here.
However, if this application ever got popular to any degree,
it would start to have some issues.
Let tell you what the issue would be.
Let's imagine that you start getting a lot of traffic
to this little, somewhat useless website
that you've put together.
As you start to get more and more traffic,
you're probably going to want to introduce
more web application servers
to respond to incoming HTTP requests,
and so in order to make additional servers,
you might create additional instances
of your Docker container
that contains both the Node application
and an instance of Redis.
The issue with this approach
is that every one of these different Redis servers
would be completely disconnected from each other.
And so one server, one Redis instance over here
inside this Docker container,
might think that the page has been visited 99 times,
but then some other Redis instance in another container
might think that it's only been visited three times.
So in general, we would definitely not want
to create multiple instances of a Redis instance
for a single app.
Instead, we would want to have one single instance,
and then if we need to scale up the web application itself,
we could just scale the Node server
and make additional instances of the Node server.
So essentially what we're going to do
is gonna be something that looks
a little bit more like this.
We are gonna have separate Docker containers
for both the Node application and the Redis server.
Each of the Docker containers that holds the Node app
will connect somehow over to the Redis instance
in this separate container,
and store the current count or current visit variable
inside of that Redis server instead.
Now, for the first iteration of this project,
we're not gonna worry about scaling just yet,
so we're really going to be setting up something
that looks like this right here.
We've got one Docker container that contains our Node app
and then a second container that has just
the Redis server inside of it.
So, with that in mind, let's take a quick break right here.
We're gonna come back the next section
and we're gonna start writing out the code
for our Node application.
So quick break, and I'll see you in just a minute.