[Intro Music]
Before creation of multiple
containers based in the same image,
let me briefly explain you what
option '-t' means in 'docker run'
command. Basically, in one of the
previous lectures in multiple
actually, we have used this option,
but I have not yet explained you what
it means. Let me first type here,
'docker run --help'; and here
you'll see this option on the list.
You could use either '-t' or
'--tty'; and it
allocates a pseudo-TTY. I'll explain you
what it does actually in a minute.
Also, if you scroll up, you'll find
option '-i' or '--interactive';
and with this option
in place, you will be connected to
'STDIN', standard input, or a
specific process that is running
inside of the container. Okay.
Let's first create container using
only '-i' option. Next, let's
try to use only the '-t' option.
And finally, let's combine '-i'
and '-t' options together.
Okay, let's do that. 'docker run
-i alpine'; and here I am now
attached to 'sh' process inside
of the alpine container; and I'm
able to list files, I'm able to
create new folders, 'mkdir test', 'cd
test'. Next, let's for example, write
some text to the file like, 'echo
'Hello from Alpine'; and let's
write this text to 'file.txt'.
Let's now list the files in the
'test' folder, and we see response
from the process and you see file
name file.txt. And now let's
read the contents of this file, 'cat
file.txt', and I should see 'Hello
from Alpine'. And yes, I see this
result. But as you see here, when
we use only '-i' option, we don't
see any command prompt, we don't see
any formatting of the output and so
on. That's why with option '-t'
Docker is able to create for
you, pseudo-TTY; and it will
actually produce some nice looking
command prompt, format results,
and so on. Let's try that. I could
try to terminate this process using
Ctrl+C, but it will not work. And
you know why is that, because this
process, 'sh' process inside of this
container does not accept such
commands. That's why you are able
either to stop container, or kill it, or
you are able to use 'exit' command
inside of this 'sh' terminal that
will exit from 'sh' process. And of
course container will be terminated
after that. Let's try that, 'exit'.
And yes, we were exited from 'sh'
process and if I list
containers now, 'docker ps', I will see
empty output, there are no
containers currently running. Now,
let's try to create same container
based on alpine image, but now using
only '-t' option. Let's do so.
Let's clear terminal, 'docker run
-t alpine',
[no audio]
and I actually see command prompt,
but I am not able to enter any
commands, and they don't get any
results from it. That's because
now I'm not actually connected to
standard in of 'sh' process. That's
why it's not enough to use only
'-t' option that will
emulate pseudo-TTY. You will not be
able to enter any commands, or get
any output from specific process.
Let me exit from this. Actually I'm
not sure whether I will be able to
do so. No, I'm not able to do so.
That's why in this case I need to
terminate container manually. Let's go
to separate tab, 'docker ps' here, and
'docker kill', and ID of the container.
Container was killed and I see
that this first session, this step
'just rang a bell!'. It's funny. Let's go
here, and I see that this process
was terminated. Okay. Let's now
launch same container with alpine
image but now using both options
'-t' and '-i'. Let's clear
terminal, 'docker run', and you are
able to use those two options
'-i' and '-t' separately like so;
or you're able to combine them and
write simply '-it'. Please
remember that now we are using two
different options, not single option
called 'it'. Great. Let's now type
name of the image 'alpine', and press
Enter. And now you see command
prompt. And if I'll 'cd' for example to
'bin', you'll see that this command
prompt will be adjusted
accordingly. If I list files here
in 'bin' folder, you will see that
they were formatted with different
colors and that's thanks to pseudo
TTY. Great. That's how you're able
to get access to specific process
using pseudo-TTY, and 'interactive' option.
That will actually connect you
to standard input and standard
output of specific process. In our
case, that was default process 'sh'
shell. Great. Let's now try to
terminate this process using Ctrl+
C, but it will not work. Reason is
the same as before. I have
explained you that 'sh' process does
not accept any system commands, but
you're able to exit from this
process as from any shell using
'exit' command. Let's type 'exit'. This
'sh' process inside of the container
will be terminated. There will be no
other processes running, and Docker
will therefore terminate this
container. Let's type 'exit', Enter, and
we get back to our terminal
prompt and if I'll list containers
now, 'docker ps', you will see nothing.
Container was exited. Great. That
is the difference between '-i',
'-t', and '-i -t' options.
Let's now try to do the same with
for example ubuntu image. Let's
clear terminal, and type 'docker run
-it ubuntu. Recap that ubuntu is
already present in our local images
cache. Container was created, and we
were logged in as root user. And
recap the in Ubuntu default command
is actually '/bin/bash'. Let me
list containers now. And here
you see this command, '/bin/bash'. This
is actually shell but it differs
from this 'sh' shell. That's why here
in this step, you'll see another
command prompt and it includes user
name and host name of this ubuntu
container. If I list files, I will
get a similar result and if I'll
'cd' for example to 'bin', list files
here, I get similar output same as I
have seen in 'sh' shell. Let's also
try to terminate this process using
Ctrl+C, also same result, but you
are able again to exit from this
process, in this case 'bash' process
using 'exit' command. And now process
was terminated, and container was
deleted as well. Let's verify that,
'docker ps', and now there are no
containers currently running. That's
all about '-t' option that
you could use with 'docker run'
command. And in most cases it is
used along with '-i' option. And those
options could be combined and you
could write simply '-it'. '-t'
option creates pseudo-TTY that
allows you to interact with
specific process inside of the
container. That's all for this
lecture. And in the next one let
me create multiple containers based
on the same image. I'll see you
next. Bye-Bye.
[no audio]