-: In the last section, we put together Docker files
for the client, the server, and the worker projects.
Now that we've got Docker files for each
of those put together that are specifically made
for the development environment, we're gonna
start putting together a Docker Compose file as well,
just as we did on the previous application.
Remember, the entire point
of this Docker Compose file, is to make sure
that it's a lot easier to start up
each of these different images as containers
with the appropriate arguments.
For example, we need to make sure that the Express server
is available on some given port.
Same thing with React Server.
We need to make sure that the worker has the ability
to connect over to Redis.
We need to make sure that the correct environment variables
for connecting to Redis and Postgres are provided
to the Express server and the worker as well.
And so this is all configuration that is going to be done
inside of our Docker Compose file.
All right, now the first container that we're going to add
of our own custom project to our Docker Compose file
is going to be the server process.
So just that Express server by itself.
At the same time, we're also going to start adding
the Postgres server, or the Postgres database
and the Redis database to the Compose file as well.
So in our development environment,
we will have a complete copy of the Express server,
a complete copy of Redis, and a complete copy of Postgres
and they're all gonna work together very nicely.
Once we get these three pieces put together
we'll then come back and start to add in
the React application, the worker,
and the Nginx server as well.
All right, now I've got a couple notes on this diagram
right here, of some of the things that we need to think
about inside of the Compose file.
So we know that we need to add in Postgres.
We know that we need Redis in there as well.
And in both those cases, we need to figure out what image
we should use for both of them.
For the server, we probably need to specify some
of the options that we had seen on the last Docker
Compose file we put together.
So we probably need to specify some build options.
For example, what Docker file to use.
We probably need to set up some volumes
to make sure that anytime we change some of our source code,
the container source code updates as well.
And then this is gonna be something
that we have not done before, but this is gonna be something
that becomes very important in this application.
We're gonna have to start thinking about specifying
some environment variables for the server as well.
Just in case you downloaded the checkpoint zip file
and you didn't go through the assembly of the server
with me, I encourage you to open up
the server directory right now.
And inside of here, you'll see a keys.js file.
This right here is a listing of environment variables
that we need to make sure are setup for this container.
So the server application needs to be given a Redis host,
a Redis port, a Postgres user, Postgres password
Postgres port, all these different environment variables.
They all need to be passed into this container
when it is executed.
And so that's something that we're going to be doing
via our Docker Compose file.
But again, we'll get to that a little bit later on
in the process.
Right now, let's get started
by creating the Docker Compose file
and we'll add a little bit of basic configuration in there
for the Postgres and the Redis applications.
All right, so inside of my root project directory
I'm not inside of any folder right now.
My root project directory
I'll make a Docker dash Compose dot yml file.
Inside of here we'll put down some of the immediate
configuration that we know that we always add
to every Docker Compose file.
I'll say version is three, like so.
After that, we'll then start to specify the list
of different services that should be made available
when we use this Docker Compose file
as a starting point for our application.
So the first service that we're going to define
will be a Postgres instance.
So I'm gonna give this a name of Postgres.
Remember that's the name of the service
as it's been added to our Docker Compose file now.
So for the Postgres project
we don't have to specify the build options
or volumes or anything like that that we did previously.
Instead, the only thing we need to specify here
is the image that we want to use
for this particular service.
And so in this case, we're gonna go up to Docker hub.
We're gonna take a look at the different versions
of Postgres that are available
and we'll specify one to be used
as the base image for our project.
So inside my browser, I'm gonna navigate to hub.docker.com.
I'll find explore on the top right hand side.
And then if we scroll down a little bit
we'll very quickly see what is the first one Postgres.
Wanna make sure I wasn't looking at Redis.
So right here on this list you should see Postgres official
very quickly pop up.
And then under the full description for Postgres
we'll see a couple of different versions that are available.
At this point in time the latest tag is associated in here-
Where is it?
Ah, here we go.
Version 10 of Postgres.
Now if you see a latest tag being applied to version 11
or even version 12 at some point in the future,
that's totally fine.
We are not using any advanced features of Postgres
right now, and so you can safely use the latest tag
probably without any issue whatsoever.
So back inside of my Docker Compose file, I'm gonna say
that the image to use for the Postgres service
will be Redis, or excuse me, not Redis.
I keep mixing the two up, Postgres colon latest.
Oh, latest, like so.
So now anytime that Docker Compose starts up,
it's gonna try to create a Postgres service using
the image Postgres, and they'll use the version of it
tagged as latest.
Let's very quickly test this out.
So I'll save this file.
I'll go back over to my command line.
I'm inside of the complex directory,
and I see the Docker Compose file inside of here.
So I will run Docker Compose up,
that will automatically pull down the Postgres image
and start up a Postgres database on my machine.
And so after a little bit of download and setup,
you should eventually see a line that says
something like, Database system is ready
to accept connections down here.
All right, so that's it for Postgres.
Now, one thing I want you to be aware of,
is that on the Postgres document or the repository,
you can scroll down quite a bit and down here
you'll eventually see something that says
start a Postgres instance.
And it shows you how to execute the Docker run command,
while specifying the Postgres password to use right here.
And if you scroll down even more,
you'll see that they are showing a lot of different
optional values you can pass in as environment variables,
so that you can customize the way in which
this Postgres image behaves.
So we are gonna make use of these in just a little bit.
So I just want you to be aware
that we're gonna come back to this page pretty quickly
and reference them this further documentation.
But right now, let's take a quick pause.
When we come back to the next section
we'll start setting up our Redis service as well.
So I'll see you in just a minute.