In the last section we ran the docker P.S. command and we saw one variation of it which was Docker.
P.S. dash dash all when we ran dash dash all on here.
We saw that we got a print up of all the containers we'd ever started up on our machine which was kind
of interesting because it kind of begs the question When does a container like really get shut down.
Why does it get shut down and what happens when it gets shut down.
So starting this section I want to start to show you a little bit around the lifecycle of a container
which is gonna give you a better idea of what's going on behind the scenes.
Now before first investigating or just jumping to the end like figuring out what happens when a container
gets shut down I want to kind of go all the way to the start and really figure out what happens when
a container is first created.
Now we've learned at this point that to start up a new container from an image we use the docker run
command.
But when we looked at this diagram remember we looked at this diagram like two or three sections ago.
You'll notice that I put some very particular terminology here I said creating and running a container
creating a container and actually starting it up are actually two separate processes.
So there's actually two additional commands in addition to Docker run that we can use to start up a
new container Docker run.
Running that at your command line is identical to running two other commands together first Docker create
and then Docker start as you might guess the docker create commands is used to create a container out
of an image and then start is used to actually start an image.
But at this point you might be a little bit curious of Hey what's the distinction between creating a
container and actually starting a container.
Let's look at a diagram that's gonna help you understand the differences between the two.
So we've looked at a diagram like this several times before remember on our image over here we've got
that kind of file system snapshot of sorts.
And we've also got a start up command the process of creating a container is where we kind of take the
file system in here and kind of prep it for use in this new Container.
When we create the container we're just talking about kind of prepping or setting up this file system
snapshot to be used to create the container to actually start the container.
That's when we actually execute the start up command that might start up the process of like hello world
or in the case of that busy box one that we use the echo Hi there or whatever process is supposed to
be executed inside the container.
So again creating container is about the file system starting it is about actually executing the start
up command.
So with that in mind let's try flipping over to our command line really quickly and we're gonna start
to investigate the differences between creating container and starting and container over it my my command
line.
I'm going to first try running the docker create and start commands with the hello world image.
So I will first do Docker creates Hello dash world when I run that command I get this long string of
characters printed out.
This is the I.D. of the container that was just created I can now actually execute the hello world command
inside of this container by running Docker start and I'm going to add on a little argument here I'm
going to say dash a we'll talk about what that isn't just a second and then I'm going to paste the I.D.
that was just emitted right here I'm going to paste in that really long series of characters and then
when I run this command we'll see that familiar welcome message appear.
So what happened here.
Well again first off we kind of prop the container by getting that file system ready.
Then after that we actually executed the primary start up command in there with Docker start.
Now what was with the dash right there.
Well to show you what's going on with that let's try running Docker start again but without the dash
a so I going to run at Docker start and then I'm going to again paste in whoops I lost the thing I've
got to do the create again very quickly so there's my I.D. and I'll do Docker start but without the
dash this time.
So when I run Docker start you'll notice that I just see the I.D. The Dash a command is what's going
to make Docker actually watch for output from the container and print it out to your terminal.
So the dash 8 specifically means hey kind of attached to the container so to speak and watch for output
coming from it and print it out at my terminal.
So when I put on Docker start dash that means give me any output that is coming from that thing.
And when I run that boom there it is.
So you'll notice that's a very small difference between Docker run and docker start by default Docker
run is going to show you all the logs or all the information coming out of the container by default
Docker start is the opposite Docker start is not going to show you information coming out of the terminal.
All right so that's the differences between Docker run and docker start hand Docker create.
Let's take a quick pause right here for you and come back the next section and we'll talk a little bit
more about exactly what it meant when we saw with the docker P.S. all that exited status.
So quick break and I'll see you in just a minute.