-: In the last section,
we found that we were able to connect to Redis CLI
inside of our running Docker container,
and notice how mine is still running over here
on the second window by adding on the -IT flag.
So when I did that,
we saw, yep, we got this prompt here,
we could enter stuff in.
I could then press control C to exit back out.
However, if I tried running this command
without the IT flag,
it appeared that I just got kicked
directly back over to my terminal.
So in this section, I wanna give you a better idea
of what this -IT flag right here is really doing for us.
The first thing you need to understand
is a little bit more about how processes run
inside of a Linux environment.
As a quick reminder,
when you are running Docker on your machine,
every single container that you are running
is running inside of a virtual machine running Linux.
So these processes are really being executed
inside of a Linux world, even if you're on Mac or Windows.
All right, so with that in mind,
in this diagram we've got three different running processes
all inside, in theory, of a running container,
or really inside of a Linux environment.
Every process that we create in a Linux environment
has three communication channels attached to it
that we refer to as stdin, stdout, and stderr.
These channels are used to communicate information
either into the process or out of the process.
Stdin, as you might guess,
is used to communicate information into the process.
So when you are at your terminal and you type stuff in,
the stuff you type is being directed
into a running stdin channel attached to,
say, the Redis CLI.
The stdout channel that is attached to any given process
is going to convey information
that is coming from the process.
So stdout might be redirected
over to your running terminal,
and that's gonna end up as being stuff
that is gonna show up on the screen.
Stderr is very similar,
but it conveys information out of the process
that is kind of like an error in nature.
So if Redis CLI has some error inside of it,
that's gonna be communicated to the outside world
over the stderr channel,
and very similar to stdout,
that's going to be redirected
to show up on the screen of your terminal.
So how's that relate to the IT flag
when we do the Docker exec -IT?
Well, the IT right here
is actually two separate little flags.
In reality, it's a -i and a -t, like so.
But by convention, we usually just kind of shorten it down
to be simply IT,
which is 100% equivalent to the two separate flags.
The -i on here means when we execute this new command
inside the container,
we want to attach our terminal
to the stdin channel of that new running process.
So by adding on the -i flag,
we are saying make sure
that any stuff that I type
gets directed to stdin of Redis CLI.
The -t flag is what kind of makes all this text
show up a little bit pretty.
Now in reality, it's doing a little bit more than that,
but at the end of the day,
the real effect that the -t flag
is to make sure that all the texts
that you are entering in and that is coming out
shows up in a nicely formatted manner on your screen.
And again, it's doing a little bit more
behind the scenes than that,
but at the end of the day, that's kind of its effect.
Let's try attaching
or doing our Docker exec on the running container
one more time and leaving off the -t flag
and just seeing what happens.
So I'll do a Docker PS to get my container's ID again,
then I'll do a Docker exec,
and then we'll do only -i this time,
I'll put the ID in, and then I'll do Redis CLI.
And so now this time,
you'll notice how I have my cursor over here.
It appears that this thing is waiting for input,
but I do not see that kind of
nicely formatted indentation I saw before.
And if I put in like set my value five,
before I had a little bit of auto complete functionality,
but this time that auto complete is definitely not there.
I can still run that command though,
and I still see, okay,
and I can still do get my value,
and I still see the value come out.
But again, all this stuff is not nicely formatted,
and so that's kind of the purpose,
more or less, kind of simplifying things here
just a little bit, of that -t flag.
Okay, so that's pretty much it.
That's the purpose of IT.
It allows us to have stuff that we type into our terminal
directed into that running process
and allows us to get information out
back over to our terminal.
So with that in mind,
let's take a quick break right here
and continue in the next section.