-: In the last section, we added in Postgres
as a service to our Docker compose file.
So now anytime we run Docker compose up,
we'll get a copy of Postgres
automatically made available to us.
We're now gonna go through the same process,
for Redis this time.
And I think you have a good idea of what we're looking for
when we look at these repositories.
So I think that we can add in this image rather quickly,
and then very quickly move on
to the server configuration as well.
So back on .hub.docker.com, I'm again on the explore tab,
I'll scroll down a little bit
and find the Redis image right here.
Here's Redis.
Again, we can look at the full description,
and find the one marked as latest.
So right now for me it's version four,
if latest is associated with version five,
or even version six at some point in the future,
again, no big issue,
it should work just fine with our application.
Now again, you might want to scroll down a little bit,
and take a look at how we can start up a copy of this thing,
along with some of the optional commands associated with it,
or additional options that you might want to add in.
Now in this case, you and I don't really need
to do any further configuration of Redis,
unlike some further configuration that we'll do of Postgres.
So if you want to, you can read over this documentation,
otherwise we'll just flip back over to our code editor,
inside of our Docker compose file,
and add it as an additional service that we need
to get our application running.
So I'll give it a name of Redis,
and I'll say the image that we want to use
is Redis:latest, like so.
Okay, so that's it for Postgres and Redis,
all we had to do there was specify the images,
a little bit later, we might come back and add in
a couple more options to configure the way they behave.
So now we're gonna move on to our server.
So on the server we're gonna see a couple of options
that are more like some of the options we've seen
in compose files before.
So we need to pass in some build options
to tell Docker compose how to build an image
out of our source code.
We need to set up some volumes to make sure
that anytime we change our source code,
those changes automatically get reflected
inside of the container.
And then we're also going to have to eventually set up
some environment variables.
Because we want to customize the way
in which our container behaves when it is started up.
And in particular, we want to customize
the way in which it finds the Redis host,
and the database and all that other good stuff.
So let's first begin with the stuff we know how to do.
We're gonna add in some specification
for the build and volumes.
Back inside of my Docker compose file,
I'm gonna add in a new service called server.
And then we'll specify the build option.
So for the build, I'm gonna first specify the Docker file
that I want this thing to use.
I want this to use the DockerFile.dev file,
so I will say DockerFile.dev.
You'll notice that I am not specifying any folder on here.
So I'm not saying like, oh yeah,
look in the server directory or something like that.
When we specify the Docker file,
we are just saying the name of the Docker file.
That's it, nothing else.
To specify that we want it to look in the server folder,
that's what the context property is for.
So every time that we've ever made use of context
in the past, we've always done something like a simple dot,
and the dot meant look in the current working directory.
But in this case, we are going to be executing
the Docker compose command from our root project folder.
And inside of the root project folder is the server folder.
So when we tell Docker compose to build an image
for our project, we're gonna say,
I want you to use a context where I want you to use
the source code inside of the server directory.
So I'm gonna provide a path to the server directory.
This means look in the current working directory,
find a folder called server, and inside of there,
use all the files and all the folders inside there
to build this image, and by the way, inside of this context
is where you are going to also find our Docker file as well.
So, that's why we are using build context here.
We are trying to specify the exact directory
that we want Docker to use to build our image out.
Okay, so that's it for specifying the build,
we'll now specify the volume to set up as well.
And just like before on our React application,
we're gonna do a very similar process.
So for volumes, we're gonna say,
a quick reminder here before we specify the volume,
if you look in this server DockerFile.dev file,
you'll remember that we specified a work directory of /app,
so everything that's relevant to us
is inside of that app folder.
So for volumes the first thing we're gonna do,
is essentially put a little bit of a block,
or essentially kind of like a little hold, or a bookmark,
on the app node modules folder.
And we're gonna say, you know what?
Inside the container, don't try to override this folder.
Don't try to override it,
don't try to redirect access to it,
just leave that folder as is.
And then in addition to that, we're gonna say,
look at the server directory,
and copy everything inside there
into the app folder of the container.
So for that I'll say ./server:app.
So now anytime our application tries to access anything
inside of the app directory inside the container,
except for the node modules folder,
it's going to essentially get redirected
back to the server directory,
inside of our current project folder.
So now anytime we make any change
to anything inside that server,
it'll be automatically reflected
inside of the app folder of our container,
and that's gonna make sure
that we don't have to rebuild our image,
anytime that we make a little change to our source code.
And again, we're gonna see a great example of that
as soon as we start everything up.
Okay, so let's take a quick pause right here,
now that we've added in a little bit more configuration,
we're gonna come back to the next section,
and we're going to start to specify
some of the environment variables inside of our container.
So quick break and I'll see you in just a minute.