In the last section we started investigating the lifecycle of a container by using the docker create
and docker start commands.
We're not going to start to investigate the status of some those containers that we've already started
up on our machine but have closed down for some particular reason.
So we can print those aloud with Docker P.S. dash dash all.
You'll notice that I have just one container listed as exited now whereas before I had like 30.
The reason for that is that I ran a command between the last video and this one to kind of pass down
that list and of course I will show you that command in just a second as well.
So at this point the only stopped or exit container that I have on my machine is this one right here.
Let's try creating and running and then stopping one more container just to make sure that we're kind
of on a level footing.
So I'm going to execute Docker run Busy Box echo.
Hi there if I then do Dr. P.S. dash dash all again and then zoom out so I can see this a little bit
better.
There we go.
I'll see the idea that container.
I'll see the echo.
Hi there.
And I can definitely verify that its status is definitely exited right now when the container is exited.
We can still start it back up.
So just because a container stop doesn't mean that it's like dead or cannot be used again we can very
easily stop and then start containers again at some point in the future to start a container backup.
We can take its I.D. and then execute Docker start and paste that idea at remember that if we use Docker
start without the dash a flag.
However we won't see any output from it and so it might be a little bit more useful to do Docker start
dash and then the I.D. And when I do that you'll notice that it printed out.
Hi there again.
Which is kind of interesting.
Let's take a look at a diagram to really understand this entire series of commands that we just issued.
All right here we go.
So we've got our busy box image and at some point time we definitely ran Docker create or Docker run
that took our file system snapshot and essentially it got a reference to it inside the container.
We then provided that override command of Echo.
Hi there.
So that was the primary running command inside the container.
That command ran it then completed the container exited naturally and we then ran the docker start command
a second time.
What happened was the running process or this primary command was issued a second time inside the container.
When you have a container that's already been created.
We can not replace that default command as soon as you started up with the default command.
That's it.
The default command is then in place.
So we cannot do something like say Docker starts Shea the I.D. and then try to replace the default command.
I can't do something like Echo by there.
So in theory this would be us trying to replace the default command again.
Can't do that.
And if we tried to run it go going to misinterpret the command that we just issued.
It's thinking that we're trying to start up multiple containers at the same time so once we have started
up a container and let it exit we can start it back up again which is going to reissue the default command
that was used when the container was first created.
All right.
Now it might seem like going over all this life cycle stuff is kind of unimportant.
It might seem like I'm going really far into the weeds with it but trust me having a solid understanding
of the lifecycle of a container is gonna be so incredibly useful later on when it really comes down
to figuring out how to troubleshoot these things and debug a running container.
So I think we got a better idea of the lifecycle of a container.
So let's take another quick break and continue in the next section.