Narrator: In last section,
we learned about the importance of the - IT flag.
In this section,
I wanna tell you about one last use
of the docker exec command.
And this use of it is probably going to be the most common
that you're going to be making use of
on your own personal projects.
A very common thing that you're going to want to do
when you are using docker, is to get shell access
or terminal access to your running container.
In other words, you are going to want to run commands inside
of your container without having to rerun,
docker exec, docker exec, docker exec
again and again all day.
So in this section, I'm gonna show you how you can open up
a shell right terminal in the context of your
running container.
So, here's what we're gonna do.
I'm gonna flip back over to my terminal.
I'm gonna verify that I'm still running.
That red is container.
I'm gonna open up a second terminal window
inside of here.
I'm going to run docker PS and get my container ID
and then I'm going to run docker exec - IT.
I'll put the container ID in.
And then here's the magic I'm gonna put in SH.
And we'll talk about what SH is in just a second.
I'm gonna run that command and you'll see that
I get the little # over here.
Once I'm in here,
I can now start to type out typical commands
that I would expect to be able to run in a
Unix environment.
So for example,
I could change my directory to my home directory,
I could list out the files and folders inside there,
nothing there right now.
Let's try going back to the root directory of \
and then if I do an LS
I'll see all the root files and folders of the container.
I could execute commands like echo hi\\there.
I can export variables,
environment variables like
export b = 5, and then echo that.
So essentially when I make use
of this docker exec command with SH over here
I get full terminal access inside the context
of the container,
which is extremely powerful for debugging.
I could even do things like, say,
run the docker CLI directly or something,
not docker CLI, but red as CLI
and that starts up, the red as CLI.
And then when I'm all done
I can hit control C
and it looks like nothing's happening.
So quick shortcut here.
If you ever are in a container
and it feels like you can't hit control C to exit
you can always try hitting command D, or excuse me
control D to get out as well.
All right, so we'll,
let's talk about what just happened there.
So we ran docker exec,
which we've seen several times before,
and then we did SH.
So what is SH?
Well, SH is the name of a program
and it's a program that is being executed inside
of that container.
SH is a command processor or a shell.
It's something that allows us to type commands in
and have them be executed inside that container.
You are already making use
of a program very much like SH on your own computer.
Chances are if you're on Mac OS
you are probably using something like Bash.
If you're on Windows,
you're probably using something like
Git Bash or PowerShell.
Me personally, I'm making use of Z Shell.
These are all programs that allow you to type commands
into your terminal and have them be executed.
And so when we start up SH inside of our container
that's just another command shell
that we can use to execute commands.
Traditionally, a lot
of the different containers that you're going to be working
with are probably going to have the SH command
or excuse me, or excuse me, the SH program already included.
Some more complete versions
of containers or images are going to also have
the Bash command processor as well.
So in some cases, you can make use of Bash directly.
In vast majority, you're probably going to
be able to run the shell inside there
to start up a command prompt and type in some commands.
Okay, So again, I think
that you're probably going to be using docker exec - IT
with SH as the command very, very often
when you start doing your own docker development.
All right, so we've spoken a whole bunch around Docker CLI.
Let's take one more break here.
There's just one or two quick topics I wanna talk
about and we'll start to move on to our next big topic.