-: In this section, we're gonna take another look at
a very commonly used command.
So the command that we're gonna look at is Docker PS.
This command will list all
the different running containers that are
currently on your machine.
Let's try running it right now and just seeing what happens.
I'll flip on over to my terminal
and I'll run Docker PS.
When I run this command
you're gonna see some headers for a table.
At present we have no containers running our machine,
so we have no entries inside this table.
At this point, we've only been running images
or creating containers that run very quickly
and then immediately close down.
So for example, when we were running Docker run BusyBox
and Echo High there, that container starts up
and then almost immediately exits us back to
the command line.
So if we want Docker PS to be meaningful at all,
we have to have some container that is running for
some longer amount of time.
In order to get a container running a little bit longer
we could substitute the command that is executed when
that container starts up.
So rather than running Echo High there,
I'll try Docker run BusyBox,
and then I'll do Ping Google.com.
This is a command that's going to attempt to
ping Google servers and measure the amount of latency.
It's a command that's going to continue running
for a quite a long time.
So here it is running right here, and as you can see
it takes about two or three milliseconds
for me to ping Google and get a response back.
This command is going to continue running
so we can now run Docker PS in a second window
and we should see this container up here in the listing.
I'm gonna open up a second terminal window
and then I'll execute Docker PS.
And when I do so, I'll then see that running container.
I'm gonna get this on one line really quickly.
There we go.
So this is a print up for the container that is
currently running that was issued the command of
ping google.com.
We also see the container's ID,
which we can use for a lot of other operations that
we'll look into later on.
We'll see the image that was used for the container.
We can see how long ago it was created.
We get a status, currently it's been up for 24 seconds.
We'll see a listing of any ports that have been
opened for outside access,
and we're gonna talk a lot about
ports later on inside this course.
And at the very end, we'll also see
a randomly generated name to identify this container.
In my case, the randomly generated name was Epic Corey.
If I now flip back over to that running ping process
I can press control C on my keyboard to stop it.
So I'll press control C right now and
I get kicked back to my command line.
As you might expect, if I then run Docker PS a second time
I would not see that container anymore.
So Docker PS specifically shows running containers.
We can modify the Docker PS command just a little bit
to show all containers that have ever been created
on our machine.
To do so, we can execute Docker PS, dash, dash all.
Oh, just two dashes, there we go.
When we execute that command, we'll see a listing of
all the containers that we have ever created.
And so I'm gonna zoom out again here really quickly
just so I can see this table.
There we go.
So for every one of these containers,
these have all been containers
that we have started up and then have either been shut down
on our behalf or shut down naturally.
So for each one of them, we'll see the container ID,
image, command, when it was created,
its current status, in this case they're all exited,
any ports that have been opened up.
Again, we'll talk about those later.
And the randomly generated name for each one.
So in practice, we're going to end up using
the Docker PS command quite a bit to see
what containers are currently running on our machine.
One of the most common uses of Docker PS is
not only to see what's running,
but also to get the ID of a running container,
because like I said,
we very frequently want to issue commands
on a very specific container, and for that we need its ID.
All right, so that's the Docker PS command.
Let's take a quick pause right here and
continue in the next section.