-: In the last section
we ran the Docker PS command
and we saw one variation of it,
which was Docker PS 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
'cause 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 wanna start to show you a little bit around the life cycle
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 had 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 startup 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 this startup command
that might start up the process of like "Hello world".
Or in the case of that BusyBox one that we used
the echo "high there"
or whatever process is supposed to be executed
inside the container.
So again, creating a container
is about the file system.
Starting it is about actually executing the startup command.
So with that mind,
let's try flipping over to our command line really quickly
and we're gonna start to investigate the differences
between creating a container and starting a container.
Over at my command line
I'm gonna first try running the Docker create
and start commands with the "hello world" image.
So I will first do Docker create "Hello" dash "world".
When I run that command
I get this long string of characters printed out.
This is the ID 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 then I'm gonna add on a little argument here.
I'm gonna say dash a,
we'll talk about what that is in just a second,
and then I'm gonna paste the ID
that was just emitted right here.
So I'm gonna paste in that really long series of characters
and then when I run this command
we'll see that familiar welcome message up here.
So what happened here?
Well again, first off,
we kind of prepped the container
by getting that file system ready.
Then after that we actually executed
the primary startup command in there with Docker start.
Now, what was with the dash A 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'm gonna run Docker start
and then I'm going to again paste in.
Oops, I lost the thing.
I gotta do the create again very quickly.
So there's my ID and I'll do Docker start
but without the dash A this time.
So when I run Docker start,
you'll notice that I just see the ID.
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 a 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 a, 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 outta the container.
By default, Docker start is the opposite.
Docker start is not gonna show you
information coming outta the terminal.
All right.
So that's the differences between Docker run
and Docker start and Docker create.
Let's take a quick pause right here.
We're gonna come back to the next section
and we'll talk a little bit more about
exactly what it meant
when we saw with the Docker PS All that exited status.
So quick break and I'll see you in just a minute.