In last section we spoke about how we make our own custom image.
We create a docker file.
We feed it into the docker server and that's going to eventually build a useful image that we can use
to start up our own custom containers.
And inside that Docker file we're gonna specify a base image run some commands and then eventually specify
command to run when a container is created out of the image.
So in this section we're gonna start working on our own custom Docker file.
Let me first tell you about what we're going to be trying to build.
So we are going to make a docker file that is going to create an image that's going to run red as server
whenever it starts up.
Now throughout this course we've already been making use of that red US image to start up red us on
our local computer.
But I want to show you how to build that thing from scratch or somewhat from scratch just to be precise.
So this is going to be going to be the purpose of our Docker file and the image that we're going to
create out of it.
So let's get started right now.
I'm going to first begin by flipping over to my terminal and I'm going to create a new working directory
or kind of a project directory of sorts and I'm going to call it Rita's image.
Like so now you can put this folder anywhere you want on your machine doesn't matter anywhere is good.
I'll then change into that directory and then I'm going to start up my code editor inside that folder.
Now quick note I am making use of visual studio code and I have configured it so that I could run it
from the command line.
So that is why I'm able to run code dot right here.
If you have not gone through those same steps you will not be able to run that command and start up
your editor essentially all you need to do right now is start up whatever code editor you like to use
and open up that reddest image directory that we just created then inside of here.
I want to make a new file called Docker file and notice how it has a capital D and it has no extension
so there's no J us on here there's no shell.
There's nothing like that.
It is simply called Docker file.
So then inside of here we're gonna write out a couple of comments to guide us through the process of
creating our custom image and it's going to essentially follow this template of steps right here.
So the first comment I'm gonna put down and notice how we create a comment by putting down the pound
symbol.
I'm going to say that I'm going to use an existing Docker image as a base I'm then going to download
and install a dependency.
And then finally I'm going to tell the image what to do when it starts as a container.
All right now I'll be honest with you the way we're going to approach this darker file where it's going
to write out all the code inside of here all the configuration we're going to use it to build our image
and then we're going to come back and talk about all the configuration that we've written inside of
here.
To be honest it's a lot easier to understand the configuration that we're going to write after you've
actually seen the process of creating an image.
So a little bit of just blind copy pasting here.
So just follow along and we'll very quickly come back and talk about the exact lines of code that we're
adding it.
So the first thing I'm going to write down is from Alpine then in the next section I'm going to add
run a P.K. add dash dash update readies and then finally on the very bottom line here I'm going to add
CMT a set of square brackets a set of double quotes and then inside there I'll put reddest dash server
like so now I'm going to save this file I'm going to flip back over to my terminal.
I'm going to make sure that I'm inside of that reddest dash image directory and I'm going to run the
line run the command excuse me docker build dot don't forget the little dot on their nose how there's
a little period so going to run that and then we're going to very quickly see a whole bunch of output
start to stream along here and then eventually I see a message that says successfully built and then
blah blah blah.
Now we're going to copy this idea right here and then run Docker run and then I'll paste that idea in
and execute this and then we're going to very quickly see all the kind of output here that we saw previously
when we ran that Docker.
So I mean the red is image and the last message I should see is ready to accept connections.
OK.
So we just went through the process of creating the docker file using it to build an image and we started
that image up but we haven't really said anything about what really happened there.
I'm going to stop the running container by pressing control see we're going to take a quick break come
back the next section and talk about exactly what we just did inside this file and at the terminal.
So quick break and I'll see you in just a minute.