Before we move on there's just one last little quick thing though and show you around this entire image
building process.
Now what I'm going to show you inside this section is not something that you're probably gonna do very
often or ever really but it's something I thought you might find a little bit interesting and help you
get a little bit of a better handle on the relationship between an image and a container.
When we were going over the flow of actions that occurred while we were building the image we spoke
about how we take an image from the previous step we create a container out of it we do something with
that container and we then essentially create an image out of that running container or that kind of
very temporally temporary container that was created.
So at this point you and I know very well that we use images to create containers but based on everything
that we've been talking about in this section it sure seems like the opposite is kind of true as well.
It seems like we can kind of take a container and generate an image out of it as well.
And that actually is correct.
You and I can manually create a container run some commands inside of it or change its file system and
then generate a usable image that we can then use at some point in the future.
In other words we can kind of very manually do the same thing that our darker file does.
We can create a container run a command like say KPK ad read this right here and then generate an image
out of that.
I want to very quickly show you how that would look.
But again I really don't expect you to do this on your own personal project.
I'm just showing you this as kind of something you might find interesting.
So let's try to kind of emulate the docker file that we just put together.
We're going to create a new container manually out of the Alpine image.
We're then going to install red lights on it.
We're then going to set up a default command and generate a usable image that can be used in the future.
Essentially everything that our Docker file just did.
So at my terminal I can execute Docker run and we're gonna start up a shell inside of here so that we
can run a couple of commands inside of it.
So going to put on the I.T. flag I'll put on Alpine as our image and then the command that I want to
execute inside there is a safe to start up a shell.
So then I get presented with a command prompt right here that is inside of that running container.
And so inside that container I'm going to manually install redness by running a P.K. add dash dash updates.
Red is like so.
So we now have a running container where we have modified its file system and a file system has now
seen the installation of reticence.
So we've got the running container.
I'm now going to open up a second terminal window and inside of here I'm going to run a command using
the docker Seelye.
That's going to essentially take a snapshot of that running container and assign a default command to
it and generate an image out of the entire thing.
So to do so I'll say first Docker P.S. to get the idea that running container and then we'll do Docker
commit.
I'm going to add on a dash C right here which is going to allow us to specify the default command.
So I can say dash C and then I'll put on CMT double quotes inside the square brace red s dash server
I'll close the double quotes or close the square brace and I'll close the single quote.
So notice how we have a single quote single quote and double quotes around it.
And then after all that I'll paste the idea of that running container.
It's going to paste it in like so and the output is the idea of a new image that we just customized
for our own uses.
Now you'll notice that this is a really long idea right here.
One shortcut that I haven't quite mentioned so far whenever you're making use of ideas or hashes in
the darker world.
You don't have to copy the entire thing.
You can just copy a segment of the start and it's kind of assume that this is going to be unique enough.
The Docker is going to take this and realize that oh you're probably talking about this very long idea
right here.
So going to copy it just an arbitrary number of leading characters here and then we'll do a doctor run
that.
And that's going to start up a new container out of the image that we just created.
And inside that running container we already have redness installed in the default starting command
will be to run red a server.
So let's run that and we'll very quickly see all the typical output that we see from a running redis
instance.
All right.
So like I said we basically just very manually created a container added a dependency to the container
set up the default command and then generated an image out of all that again.
You really don't want to use that practice in general if you don't use Docker commit in general you
really want to use the docker file approach because it allows you to very easily rerun that series of
steps again in the future.
But again I just thought you might find it interesting how.
Yes there really is a very kind of fluid relationship between containers and images.
All right.
So let's take another quick pause right here and we'll move on to the next section.