[Intro Music]
Before going on with Python, let me
demonstrate you how you're able to
remove containers and prune
containers. Because at the moment,
there are actually a lot of
containers that we have created
before, but now they are stopped.
Also, you are actually able to
start over any stopped container.
Actually, at the moment, there are
still two nginx containers running.
Let me stop them. And afterwards,
I'll demonstrate you how to start
over stopped container, remove stopped
container, and prune all stopped
containers. Let's do that. Let me
stop this container, and let me
stop this one as well. And I don't
need the two windows anymore. Let
me use just one like this. And I
could go out from the nginx1
folder. Let's 'cd' to
'containers', and let's clear
terminal, and let's list
containers that are currently
running. And as you have guessed,
probably there are no containers
running at the moment. But if I
enter 'docker ps -a', you
should see all previous containers
starting from the very first one
where we have used the hello-world
image. Also, if you scroll to the
beginning of this output, you
should see nginx containers that
were exited just several minutes
ago. Here are those containers in
my case. And you see that this
container was exited 30 seconds ago
and this one 48 seconds ago. And those
containers were created 24 hours
ago. Great. Let me now demonstrate
you how we are able to start over
stopped containers or exited
containers. Let me for example, try
to run over this container with
name 'nginx2'. Let's do so. Clear
terminal. And for that you could
use Command 'docker start', and
ID or name of the container. We
have created named containers, that's
why I'm able to use those names
here, nginx1 or nginx2.
Let's use 'nginx2' name here.
Container was started, and I could
verify that using 'docker ps'
command. And you'll see that now
this container is again up and
running. Let's verify whether I
will be able to connect to this
nginx server or not using this
external port. Let's go to web
browser, actually I have those two
tabs open, let me close this one, and
let's refresh this page, and you
see that it actually works. And it
works even if I am located not
inside of the nginx2 folder.
You see that now I am in 'containers'
folder. In this case it does not
matter because this container is
actually configuration has mapping
of specific folder, 'nginx2'
folder to internal folder inside of
the container. That's why there is
no need to move into nginx2
folder, and start container there.
Let me actually verify whether I
will be able to modify files. Let's
go to nginx2 folder, index.html,
and add one more exclamation mark
here, go to web browser, refresh page,
and yes it works. That's how
you're able to start over any
stopped container. As a challenge
you could start for example nginx1
container, and verify whether it
will still work or not. Also as a
challenge you are able to try to
start any other of the stopped
containers. Next, let me now first
stop this container, and I am
able to use Command 'docker stop', and
use either ID of the container or
its name. Let's use first few
characters of the ID, '6e', and
container was stopped. Let's verify
that. 'docker ps', and yes there are no
containers currently running. But if I
list the containers in the history,
I'll still see nginx2 container,
here it is with nginx2 name. Great.
Let me now demonstrate you how we
are able to remove a specific
container from this list. For that
you could use the command 'docker rm',
or 'docker container rm'. Let's first
try 'docker rm'. Let's clear
terminal, 'docker rm', and here type
name or ID of the container, let's
type nginx2. Container was
removed. And now if I list
containers, 'docker ps -a', scroll up,
[no audio]
I will see that there is no nginx2
container anymore. And basically
we have performed this action
before in one of the previous
lectures when we have tried to
create a container with the same
name; and Docker does not allow you
to do so. It is not possible to
create containers with the same
name even if a container was
stopped. Great. Let me now try to
stop any other container, actually,
sorry, remove container, and let me
do so with a container with this
name. Let me copy this name, it was
ubuntu container, and let's use the
'docker rm' command again, and paste
here name of that container,
and container was removed. Let's remove
for example also this one. Let me
copy this name. In your case, you
could choose any other names of
your containers because those names
were randomly generated, that's why
in your case names will be
different. 'docker rm', paste this name,
and this container was removed as
well. If you want to remove all
stopped containers just in a one
shift, you are able to use the
command 'docker prune'. Let me
actually use 'docker --help'
command and show you a description of
that command. And we need to
basically use Management Command,
Container Management Command. Let
me scroll up, and this command
should be used. So let me type here
'docker container --help',
instead of simply 'docker --help'; and
here you'll find a list of commands
that you are able to use with
Container Management Command. And
here is 'prune' command that will
remove all stopped containers. And
now's a good time to remove all
stopped containers just in one shift
using one command 'docker container
prune'. Let's do that. Let's clear
terminal, 'docker container
prune'. 'This will remove all stopped
containers. Are you sure you want
to continue?' And if you are sure,
just type 'Y', and press Enter; and
all containers were removed. And
the total reclaimed space is 766
bytes. It is less than one
kilobyte. And that is actually the
beauty of Docker, all those
containers that were run before and
that were stopped afterwards used
less than one kilobyte of disk
size. All right. That's how we were
able to remove all stopped containers.
And you could verify that using
'docker ps -a', and you'll see no
containers here in the history.
Actually I have forgotten to
demonstrate you how you are able
to remove multiple containers using
multiple IDs. Let me quickly
demonstrate you that. Let me clear
terminal and quickly run two
containers, for example, 'docker run alpine'
[no audio]
and 'docker run alpine' once
again. And now I should have two
stopped containers. And yes, that
is the case. And now let me use
'docker container rm' command,
actually it is equivalent to 'docker rm'
command, and here I could type
multiple names or multiple IDs of
containers that I want to remove.
Let me type here '05' like so, and
after space '78', starting
characters of those IDs of those
two containers, this one and this
one. Let's press Enter. And both
containers were removed. 'docker ps
-a', and I see no containers on
the list. That's how you're able to
use either 'rm' command or 'prune'
command. And if you don't need
containers anymore, from time to
time run those commands in order to
clean space and in order to free
namespaces. That's all for this
lecture, and next let's move on to
python image, and create the
container based on python image.
Let's do that next. Bye-Bye.
[no audio]