[Intro Music]
Okay guys, so we have just created a
very first container using a
hello-world image. We have pulled
it from a Remote Registry called
Docker Hub and afterwards I have
created container and this
container has printed some text to
the terminal. Also in this text
you see suggestion to try another
container with this command
'docker run -it ubuntu bash'. And
with this command we will be able
to create another container using
ubuntu image. But let's try it
without option '-it', and 'bash'.
Simply as we have tried with
'docker run hello-world'. Let's now
type 'docker run ubuntu', and that's
it, and let's see what will happen. Let me
clear terminal, 'Ctrl+K', and here
let me type 'docker run ubuntu'.
You see that we again we are not
able to find the image 'ubuntu:
latest' locally. And that's why we
have started pull operation from
Remote Registry Docker Hub and you
see that we have pulled several
times and you see here different
IDs. Now, I will not explain you
what it means. We will get back
to it later on when I will
explain you how Docker works under
the hood. For now, you should
understand that we have simply
pulled image called ubuntu from a
Remote Registry Docker Hub. Also
you'll see sha256 Hash, same as we
have seen for hello-world image, but
of course hash itself is different
here from the hash for hello-world
image. Also, you see finally the
image was downloaded, it's status is
downloaded; but afterwards after we
have executed basically 'docker run
ubuntu' command, we have returned to
terminal, it means that actually
nothing happens. And we are not
able to do something inside of the
ubuntu container. But it was
immediately terminated afterwards.
Why? Because there was no command
that was executed inside of this
ubuntu container. And if there are
no processes running inside of the
container, Docker automatically
terminates the container. And if I
enter 'docker ps' now, you will see
that there are no containers
running. But I am able to observe
history of the containers that were
exited. For that you could use
command 'docker ps' with option '-a'
like so. And now I will see that
there was container that was based
on ubuntu image, and there was
command, this one that was executed
automatically, here is this
command. But we have not performed
anything inside of the bash, inside
of the container. That's why
container has decided that bash
should exit, and it was exited,
process was terminated. And
afterwards, Docker has exited
container as well. That's why here
you see that the status of this
container is 'Exited About a minute
ago'. Also you see information about
previous containers that we have
created in the previous lecture.
And we have used there hello-world
images, here, and here. We have
created basically two different
containers, and you see that they
were exited about an hour ago.
Okay, that is the status of this
container that we have tried to
create using 'docker run' command.
Also, if I will list now local
images with command 'docker images',
I should see here ubuntu image
on the list. That means that if
I'll try to create one more
container using Uubuntu image, it
will be created using the same
image as you see here, there was no
need to pull the same image from
Docker Hub. Let's try that again.
And let's try it with the same
command as we have used before,
'docker run ubuntu', and we see actually
nothing. But again, under the hood,
Docker has created a new container
based on this image. There was no
need again to pull it from Docker
Hub, because we already have it
here on the list. But afterwards
container was again automatically
terminated. Let's have a look at
history of containers. 'docker ps
-a', actually there is
alternative command to 'docker ps',
and this command is 'docker
container ls', and if l type here
'docker container ls -a', you'll
see actually same result as with
'docker ps -a', it brings us
history of all containers that were
created before. And again you see
here one more container that was
created using ubuntu image, and this
container was exited a minute ago.
Here below you see a second
container with the same image
ubuntu, but this one was exited 4
minutes ago. It means that each
time when you execute the command
'docker run' and some image,
Docker creates a new container
based on specific image. But now
you may ask me a question, how we
are actually able to log in into
that container, ubuntu
container, and execute some commands
inside of the Ubuntu operating
system. Answer is pretty simple.
Let me show you. 'docker run -
it ubuntu'; let's press Enter and
see what will happen. And now you
see that I have basically entered
bash shell inside of the Ubuntu
container, and I have logged in
automatically as a 'root' user, here
you see that. And here is actually
ID of this container that was just
created. And now I am still inside
of this container, and container is
still running. Let me show you that it
is still running. Let me open up a
new tab here in terminal, and let's
enter 'docker ps' command. Here you
see image that was used, this ubuntu,
and also you see here CONTAINER ID,
and this ID is the same as you see
here in this bash shell inside of
the ubuntu container. And now
actually, we are able to perform
some operations inside of this
container. For example, let's use
ls command and list files inside of
the ubuntu container. And here you
see some set of folders. And for
example, you are able to list the
files inside of the 'bin' folder.
Let's do that 'ls bin', and you'll see
some set of executables that you
are able to use inside of the
ubuntu container. Again, please
notice that this set of files and
folders is completely isolated
inside of this ubuntu container. It
is not a set of files on my macOS
computer where I am running Docker
right now. Actually, let me show
you that to prove that. Let me
open up one more tab, and here
let me 'ls', and you'll see actually a
list of folders on this macOS
computer. And also I'm able to list
the actually files in '/bin'
folder, and you'll see a set of
executables on my macOS computer.
And this set of executables is of
course different from this set of
executable files. That's how you're
able to list the files inside of
the container. And again, container
is still running. You could verify
that here, 'docker ps', and you see
that there is container with ubuntu
image that is up and running and it
is 'Up 2 minutes'. And also you see
here which command was executed '/bin
/bash', it is bash shell, and we are
actually located now in this bash
shell. Okay, please notice that
this container runs now full
featured Ubuntu operating system
and you could verify version of
this operating system using 'cat
/etc/os-release'.
You see here version Ubuntu 18.04.4
Long Term Support release.
Also we could try something else.
Let's try for example 'echo' command.
Let me clear terminal; and type
echo "Hello from Ubuntu
container", Enter, and you'll see
"Hello from Ubuntu container", here in
this shell. Please notice that we
are able to use this command
because there is such executable
inside of the bin folder. Let me
list contents of the bin folder once
again. And you'll see here 'echo' on
the list. Let's try something else.
Let's clear terminal, and type 'hostname'
command; and you'll see here
hostname of this container. It
actually matches with this ID here
on the list. Also, we're able to verify
which IP address was assigned to
this container using command 'hostname'
-i', like so, and you'll see
IP address 172.17.0.2 here in this
output. Great. That's how you're
able to perform some commands
inside of the ubuntu container.
Let's now type 'exit', and let's exit
from this bash shell. 'exit', and we
can return back to our terminal.
Let's now list the containers that
are currently running, 'docker ps', and
you'll see empty output. Basically
you're able to use alternative
command to 'docker ps', 'docker
container ls'; and you'll see same
result. There are no containers
currently running. But if I enter
'docker ps -a', you'll see that
our ubuntu container was exited 34
seconds ago. Why it was exited?
Answer is pretty simple. We have
exited from bash shell inside of
the container, and that terminated
bash process inside of the
container. And when there are no
processes running inside of the
container, Docker simply terminates
such container. That's what actually
happened here in this example.
Great. Let's also clear
terminal and let's have a look at
the size of the image that was downloaded
for ubuntu containers,
'docker images', like so. And here
you'll see size equal to 64.
megabyte. It is of course much more
larger than the size of the hello-
world container that was simply
less than two kilobytes in size.
But this size is relatively small
in comparison to let's say, Docker
installation itself that was around
two gigabytes for macOS or Windows
computer. But this size is still
large in the Docker world, because
we have used here full featured
Ubuntu operating system. And in the
next example, I would like to
demonstrate you how you're able to
create the Linux container using
smallest image possible. Let's try
that next. Bye-Bye.
[no audio]