-: In the last section,
we spoke about how we make our own custom image.
We create a Dockerfile, 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 Dockerfile
we're gonna specify a base image, run some commands
and then eventually specify command to run
when` a container is created outta the image.
So in this section,
we're gonna start working on our own custom Dockerfile.
Let me first tell
you about what we're going to be trying to build.
So we are going to make a Dockerfile
that is going to create an image that's going to
run Redis server whenever it starts up.
Now, throughout this course,
we've already been making use of that Redis image
to start up Redis on our local computer,
but I wanna show you how to build that thing
from scratch or somewhat from scratch just to be precise.
So this is gonna be going to be the purpose
of our Dockerfile
and the image that we're going to create out of it.
So let's get started right now.
I'm gonna 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 Redis 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 gonna 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 am 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 Redis image directory that we just created.
Then inside of here,
I'm going to make a new file called Dockerfile
and notice how it has a capital D and it has no extension.
So there's no JS on here, there's no shell
there's nothing like that.
It is simply called Dockerfile.
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 gonna 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 gonna 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 gonna 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 Dockerfile
we're just gonna write out all the code inside of here,
all the configuration.
We're gonna use it to build our image
and then we're gonna 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 gonna write
after you've actually seen the process of creating an image.
So a little bit of just blind copy pasting here, okay,
so just follow along and we'll very quickly come back
and talk about the exact lines of code that we're adding in.
So the first thing I'm gonna write down is from Alpine.
Then in the next section I'm gonna add
RUN apk add --update Redis.
And then finally, on the very bottom line here
I'm gonna to add cmd, a set of square brackets
a set of double quotes,
and then inside there I'll put Redis dash server like so.
Now I'm gonna save this file.
I'm gonna flip back over to my terminal.
I'm gonna make sure that I'm inside
of that Redis 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 there.
Notice how there's a little period.
So I'm gonna run that
and then we're gonna very quickly see a whole bunch
of outputs start to stream along here.
And then eventually I see a message that says
successfully built and then blah, blah, blah.
Now we're gonna 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 seeing the Redis image.
And the last message I should see
is ready to accept connections.
Okay, so we just went through the process
of creating the Dockerfile, 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 gonna stop the running container by pressing control C.
We're gonna take a quick break, come back
to 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.