In this section we're going to start to really get a better idea of what was really occurring on our
terminal when we executed that docker build command.
We're going to walk through each of these steps and not really analyze the structure of each of them
but really analyze the effect that they had on the image that we were building.
So to get started I first want to talk a little bit about the output that we saw in our terminal when
we executed the docker build command.
So first things first.
Why do we use Docker built.
Well this is a new command that we have not been used before.
Tied to the docker CLIA.
Remember what we said a little bit ago when we create our Docker file.
We then feed it into the docker client which turns around and gives your file off to the docker server
and that's what builds your usable image.
So when we ran Docker Bill dot that was us giving our Docker file off to the docker CLIA that built
command is what we used to take a docker file and generate an image out of it.
The dot right here is specifying what is called the build context the build context is essentially the
set of files and folders that belong to our project.
It's a set of files and folders that we want to kind of encapsulate or wrap in this container and we'll
see some better examples of exactly what the build context is used for later on throughout the course
as our Docker builds start to get a little bit more complex after running that command.
We then very quickly saw a whole bunch of output start to scroll on by the first thing I want you to
notice here is that for every line of configuration we put into our Docker file we got an additional
step added to this flow.
So I see step one of three corresponds to the first line of our Docker file.
I see it step two or three corresponding to the second line.
And by that you can guess the third one down here.
Step three of three correspondent to the third line of the docker file now with the very first step
where we said from Alpine the first thing that occurred was the docker server looked at our local build
cash and it check to see if it has ever downloaded an image called Alpine before in our case it probably
hasn't.
So the first thing that occurred was the docker server reached out to the Docker Hub which you'll recall
is a repository of existing Docker images that are free for public use.
And it downloaded that image the image called Alpine.
So pull complete means Yep it was successfully downloaded and well it really tells you that very clearly
right here it downloaded newer image for Alpine latest.
So that for separate they're kind of boring.
We basically just downloaded an initial starting image to use as a base.
Things started to get a little bit more interesting on step number two right here.
So there's a couple of lines of code or output right here.
I want you to really take a very good look at.
You'll notice the first line right here says running in and then an I.D. that's very key right there.
And once you remember that for just a second and then a little bit lower you'll notice that it says
removing intermediate container and it printed out the exact same I.D. that we saw back up there.
So it looks like this idea right here is the I.D. of a container.
But what container.
We'll dive into that in just a second.
When we look at a diagram that's going to Coote to kind of explain this flow.
You'll notice that we also saw some very similar output down here for step three as well where it said
running in blah blah blah and then very shortly after that removing intermediate container.
One last thing I want to point out here is that four step number one up here.
You'll notice that there is no kind of like intermediate container printout.
So it appears that for every instruction that we added to the docker file the sites the first one it
appears that some like container of sorts was created.
So that mind is flip over to a diagram and really walk through what just occurred.
All right.
Now I know we're going through this stuff like really intense and in-depth but honestly getting a very
fundamental or solid understanding of this docker build process is really going to help you understand
Docker in general.
That's why we're going through so much detail.
OK.
So in this diagram we've got a container on the right hand side.
We've got the Alpine image on the bottom left and then our series of three commands over here.
So the first thing we did was specify from Alpine and as we saw that basically went out and downloaded
the Alpine image off of Docker Hub.
Remember that an image has a file system snapshot and some start up commands.
And at this point we don't really know what the start of the command for Alpine is.
But you know we don't really care that much the next line was the run KPK.
Add Update Read this.
So here's exactly what happened behind the scenes when Docker server saw this line of configuration
right here.
It looked back at the last step that just occurred.
So it looked back at this step the from Alpine step it looked at the image that came out of that previous
step.
The image that came out of the previous step was the Alpine image.
Then on the run line right here it took that image and created a new container out of it.
So in memory we've very temporarily got a brand new container created at the very start of Step number
two.
And that's what this running in blah blah blah right here means.
It means that it created a temporary container out of the image that was sourced during the previous
step.
So it can kind of imagine that we took the entire file system snapshot from the Alpine image and we
stuffed it into this very temporary container that was created just for the second step right here or
the second instruction after creating this temporary container this command right here the commander
we just added on was executed inside that container as its primary running process.
So we took that run command.
We took that line or that full command right there and we executed it as a process inside of the container.
So this is this containers primary running process as we said in the last video.
AP K is a package manager that is built into the Alpine image.
So this command executed inside the container.
And while it executed it went through the process of downloading reticence.
That's what happened right here.
It downloaded and installed readies in a couple of dependencies for readies so you can imagine that
during that installation process we maybe got some like new folder on this containers harddrive right
there maybe was something called like simply read us now you know I want this to represent the reddest
program.
It didn't install it in the root directory or anything like that but let's just imagine that a peak
ad downloaded and installed is onto this containers a little hard drive right here.
So we now have a container that has a file system snapshot that contains the newly installed copy of
Redis.
Now look at what happened immediately after that after that container or something after that package
was installed.
We then stopped that container.
We took a file system snapshot of that container and then we stopped it entirely.
So we're saying right here that temporary container that was just created we stop it and we then take
its current file system snapshot and we save it as a temporary image with this idea right here.
So the output of everything inside of Step number two is a new image that contains just the changes
that we made during this step so we can now kind of imagine that this idea right here.
This is the I.D. to a very temporary image.
So I'm now going to update the image down here on the top left hand side.
I'm going to say that is the 3 8 easy image.
And inside that image it now has a installed copy of Rectus
and we also threw away that intermediate container.
So that is the end result of step number two.
In total we created a temporary container out of the Alpine image.
We executed this command inside that container and then we took that containers file system and saved
it as a temporary image.
So we now have this very temporary file system snapshot right here that has red is included.
Then we move on to Step number three where we execute CMG right here so that you can imagine what happens
here with CMT.
We're going to look at the image that was generated during the previous step.
So in this case the image that was taken from the previous step is this 3 8 easy image we create a new
very temporary container out of it.
And when we make that container we take the images file system snapshot and stuff it into this container
and then with the ACM D this is setting the primary command or the primary process of the container.
So the container does not actually execute read a server.
It doesn't execute this command.
It just tells the container hey like just so you know if you were to ever run for real you should be
running read a server as your primary command so the container is told this is supposed to be your intermediate
or or.
This is supposed to be your primary command and then it shuts down that container and takes a snapshot
of its file system and its primary command.
So the end result is successfully built this idea right here.
This is the final image that was created out of this entire series of steps.
So in Step number three at the very end we remove the intermediate container.
We take a snapshot of its file system and its primary command and then we save it as an output as an
image with an idea of FC 6 0.
So here's the container.
The very temporary one we take a snapshot of its file system song and to put it over here and we also
take a snapshot of it's running a primary command or is not running primary command but primary command
that should be executed when the container starts up in the future.
And so we specify the start up command as a server and then we save that entire thing as an image with
the idea of FC 6 0 and so the end result is this right here the end result is our image with that I.D.
that has our full file system snapshot with red is installed in a startup command that has been specified
All right so at long last that is the full story.
That is what happened with the docker file.
Now the real takeaway that I want you to understand here is that basically along every step along the
way not basically every step but really every step along the way with every additional instruction we
essentially take the image that was generated during the previous step.
We create a new container out of it.
We execute a command in the container or make a change to its file system.
We then look at that container.
We take a snapshot of its file system and save it as an output for the next instruction along the chain.
And then when there is no more instructions to execute the image that was generated during that last
step is output from the entire process.
As the final image that we really care about who.
So that's a lot of information.
So let's take a quick pause right here and we'll continue in the next section.