-: In the last section, we put together our default.com file,
and now we're going to put together a docker
file that will create a new custom Nginx image
and attempt to apply this configuration file to it.
Now, if that sounds hard, let me assure you,
it's gonna be way easier than you ever might guess.
Let's first begin by pulling up Docker hub.
And I wanna very quickly look
up the Nginx image,
that we can download automatically from Docker hub.
So, I'll go to hub.docker.com.
I'll go to the explore tab up top,
and then, as the very first results,
or hopefully it'll be one of the first ones for you,
sometimes it kind of argues with Alpine for top spot,
I'll look at Nginx.
So, we'll look at the full description here.
As usual, you'll notice there's a bunch of links for help,
and you can look down here,
and eventually you're gonna see somewhere inside of here,
uh right here.
Here is a great example right here.
So, in order to do any customization of Nginx,
essentially all we have to do is build a docker file
that says,
we wanna make a image from Nginx,
and then we're gonna take our configuration file
and copy it into the temporary container,
or essentially the image.
All the configuration for Nginx is done by these files
or these configuration files that simply exist
on the hard drive.
So, as long as we, or excuse me, not the hard drive,
but you understand the file system.
So, as long as we copy that configuration file
into our image, it'll be automatically applied to Nginx.
once a container starts up out of our custom image.
Essentially, what you see right here,
is all we really have to do inside of our docker file.
Remember that,
if we do not replace the default command
of a image inside of the docker file
then the default command of the parent image,
which is from Nginx right here.
will automatically take precedence.
Okay, so let's get to it.
I'm going to flip back over to my code editor
inside the Nginx folder.
I'll make a new file called Dockerfile.dev, and then inside
of here I'll set up the base image with from Nginx.
And then we're going to copy the default.conf file
into the file system of this image.
So I'll say copy default.conf, and technically we should do
on a relative path like so.
And then the folder that we're going to copy it
over to is, /etc
Nginx conf.d.
Now, in every other case we've ever made use
of this copy command, we've been copying files
into a directory.
We can actually specify the exact file name to copy our file
into. And if that file already exists inside the image
then it will be overwritten.
So there is a default.conf file that is included with
Nginx by default.
So by putting on default.conf right here, we're saying very
clearly yes, take my file and overwrite the
Existing one, just overwrite what is ever is there.
And that's exactly what we want to do in this case.
We want to overwrite that default file.
All right, so that's pretty much it.
I'm gonna save this,
And now the last thing we have to do is add this
Nginx as a service word docker compose file.
So I'm gonna open up Docker compose file
and we'll add in a new Nginx service to this thing.
Now I'm just gonna add it
towards the top here just cause I'm lazy.
It doesn't really matter where you add it.
Okay, so the new service will be called Nginx.
We could just as easily have called this like our router
or our proxy or whatever you want to call it.
In this case, I'll just call it Nginx just
because I don't really have a better name
off top of my head.
Now this is definitely a service
so we want to make sure is always running ahead
a hundred percent of the time no matter what.
And so I am gonna use that restart policy that we spoke
about a while ago on here.
So I'm gonna re say restart.
Always like so, because no matter what
I always want to make sure Nginx is ready to go
if the API crashes or if my say worker crashes.
If the worker crashes in particular
I'm definitely okay with this thing just crashing
out and burning and staying off.
Cause remember the worker is doing the processing
for our actual fibonacci value
and that is kind of a expensive computation.
And so if the worker is misbehaving in some way
I kind of am okay with it just crashing
and staying off because I wouldn't want it to
be accidentally consuming a ton of CPU cycles.
But in the case of Nginx
this thing is routing traffic to our entire application.
And so no matter what, I gotta have Nginx running.
So then inside of here we'll also specify a build cause
we have a custom version of Nginx that
we're putting together.
So I'll specify its Docker file as docker file.dev
and I'll set up its context as the Nginx directory.
And then finally, unlike a lot of the other
things we put together inside of here
this will have a port mapping.
So I'm gonna say ports and I want to map, how about port?
I don't know, 30 50 on my local machine should be mapped
up to port 80 inside the container.
So remember you and I
once we start up Docker compose, we're going to
be accessing this port right here on local host.
And so if you want something else here
you could do, you know, 4,000, 3,000, whatever it might be.
Totally up to you.
All right, so I think that's just about it.
Let's take another pause right here.
Make sure you save this file
and then we'll test everything out in the next section.
So I'll see you in just a minute.