Instructor: In this section, we're gonna start
to set up development Dockerfiles for our server
and worker projects.
The development Dockerfiles
that we're gonna use for both these
are gonna be just about identical
to what we just did for the client.
So we're gonna go through these pretty darn quickly.
Inside of my server folder,
I'll make a new file called Dockerfile.dev.
Inside of here, we'll specify the node alpine image
again as our base.
So I'll say from node:alpine.
We'll set up a working directory of app.
We'll copy over the package.json file.
I will run npm install.
We'll copy over everything else.
And then finally, we'll set up our default command.
Now, in the development environment,
the startup command
is gonna be just a little bit different
for the server and the worker.
If you open up the package.json file,
you'll notice that we set up a dev script
in both of these, of simply nodemon.
Nodemon is a little command line tool
that can be used to automatically reload
your entire project whenever any of the source code
inside of your project is changed.
And so we're gonna take advantage of that
as we are running our docker containers
to make sure that anytime we set up a volume
and our source code changes and the volume updates as well,
we'll get our application to automatically
restart with the nodemon tool.
Explaining this with words is a little bit challenging.
It's one of those things
where it makes a lot more sense to see it in action.
So let's just put together the Dockerfile
and you'll see this in action very quickly.
The last thing we have to do inside of here
is specify the primary command.
We'll do npm, run, dev.
I'll save this file,
and then I'll make another file
identical to it inside of the worker directory.
So in the worker folder,
I'll make a new file called Dockerfile.dev,
and I'm gonna copy everything
from the first one into the second one.
So now they both have a primary command of npm run dev.
Let's now try building images out of both these projects.
It should go pretty quickly.
So I'm back inside of my complex folder.
I'll change into server and inside of here,
I'll do docker build -f Dockerfile.dev.
And then don't forget the dot at the very end.
That's gonna run the npm install,
but for the backend API server,
the npm install is gonna go much more quickly
than it did for the front-end application
because we have far fewer dependencies.
Again, if you see any warnings there,
totally okay, no issue with that.
Here's our image ID.
We'll test out very quickly with a docker run ID.
You might notice this error right here
of connection refused.
That's totally fine.
We're seeing this message
because we are not running a Redis server
or a Postgres server right now.
In particular, this error message
is coming from the lack of a Postgres server.
I'm gonna stop that by hitting Control + C,
and we'll go try building out our worker process as well.
So in my worker directory,
I'll do a docker build -f Dockerfile, oop,
Dockerfile.dev period.
It's gonna run the npm install here again.
Again, this will be very quick because we have very,
very few dependencies on the worker project in particular.
I see a couple warnings, again, non-issue there.
We eventually end up
with our ID and I'll start up a test container with that.
And everything's looking pretty good.
No error messages whatsoever.
Okay, I'm gonna stop everything
by hitting Control + C and I'll change back
out to the complex directory.
And I think that's pretty much it
for the development Dockerfiles.
So let's take another quick pause
and we'll continue in the next section.