-: In the last section,
we made use of Docker volumes
to automatically get changes that we make
to our source code
reflected inside the container.
Now, the only downside to this approach
is the ridiculously long docker run command
that we have to execute at our terminal.
If we stop our running container,
you can press up arrow again
depending on your terminal
to get that command back up.
And so you can see that there's a lot of options on here.
We have to specify the port.
We have to specify two volumes
and then we have to specify the image id.
So clearly this is kind of a pain right now
to run this command long form.
Well, quick reminder,
what did we learn about just a moment ago?
Just a moment ago,
we spoke about Docker Compose
and the whole purpose of Docker Compose
is to make executing Docker run easier.
And so even though this time around,
we have a single container image
or a single docker image,
we can still make use of Docker Compose
to dramatically simplify the command we have to run
to start up our Docker container for development purposes.
So let's create a Docker Compose file
and inside that file
we're going to encode the port setting
and the two volumes that we need
to create inside the container.
I'm gonna flip on over to my code editor
and inside of my route project directory,
I'm gonna make a new file called docker-compose.yml.
Now, the composed file that we're gonna create
is gonna look rather similar
to the one we just put together.
We'll first begin by specifying
a version of three,
inside of quotes.
We'll then set up a list of all the different services
or containers that are going to be created
when we run Docker Compose up.
Now, previously, you'll recall
we named our initial service something like Node app.
We could call this one React app.
We can call it Web. Anything you want.
I'm gonna go with Web here.
Just because it makes a little bit of sense.
Next, we need to specify the image
or some of the Docker file that we're going to use
to create this initial container.
Before we were able to just specify Build Dot.
However, when we use Build Dot,
that assumed that we had a Docker file
inside of the current working directory.
Let's try just sticking with Build Dot for right now
and seeing if that's gonna work out.
Even though our file name is a little bit different.
Let's just see what happens.
The next thing we're going to specify is ports.
So remember we can specify a list of ports here.
So just indicate a list.
We put down a single dash.
I'll then put down my quotes
and I'll say that I want to map up port 3000
outside of the container to 3000 inside the container.
And then finally, and this is the real good part.
This is the part where we can do
a shorthand for specifying our different volumes.
We'll say volumes a dash.
And we'll say that we wanna do app node modules.
Remember this one right here
is essentially going to say,
do not try to map a folder up against app node modules
inside the container.
And then as the second entry,
we'll do a dot,
which indicates the current working directory.
A colon.
And then we'll say that we want to map
that folder outside of the container
into the app folder inside here.
The dot.
So the current folder outside the container
to the app folder inside the container.
There we go.
And that's pretty much it.
So now anytime that we want
to start up our development instance
or development container,
we don't have to do
that really long docker run command,
like this one right here.
Instead, all we do is Docker Compose up.
Let's try running it right now
and just seeing what happens.
So again, inside of my front end folder,
I'll do Docker Compose up.
Now as you might have expected,
we're getting an air message right here
that says, "Cannot find a docker file."
Because
when we put together our initial service
or the initial container right here,
we said, Oh yeah, build using the current directory.
But inside the current directory,
we don't have a Docker file.
We have a docker file.dev file.
Let's take a quick break.
In the next section, we're gonna figure out
how we can force Docker Compose to build our image
for this web service right here using that dev.dev file.
So quick break and I'll see you in just a minute.