-: In the last section, we spoke about
how we could open up a shell inside
of a running container by using docker exec -it,
and then passing in shell
or just simply sh as the command that we want to execute.
We've been talking about all this
in the context of the exec command
which we can use to execute an additional command
inside of a container.
But if we wanted to, we could also run docker run,
the original docker run command right here
along with that it flag
and start up a shell immediately
when a container first starts up.
Now, of course, if we start up a shell
right when the container first starts
that's going to displace
or keep any other typical or default command from running.
But sometimes, it is quite useful to get a empty container
with a shell inside of it and just being able to poke
around and not have any other process running.
So let's try that out right now at our command line.
I'm gonna flip back over to my terminal.
I'm gonna run at docker run.
I'm gonna put on the it, so that we can attach
to standard in on the process that we're about to start up.
I will run the busy box image
and then the program or the primary command
that we're gonna execute inside the container will be sh.
So this means start up a new container
out of the busy box image,
run the sh program, which is a shell
and attach to standard in of that program.
So when I run this, I'll be presented with a command prompt
and just like we saw a moment ago, I can run the LS command
I can ping google.com and hit control C to stop it.
I can echo a message, whatever I wanna do.
Again, this is a command that you might be using
somewhat frequently anytime
that you want to poke around a container.
The downside to using docker run with it and sh
is that chances are you're not going
to be running any other process.
It's a little bit more common
that you're going to want to start up your container
with a primary process of like maybe your web server
or whatever it might be
and then attached to it a running shell
by using the docker exec command,
wherever it is right here.
But I just wanted you to be aware
of this alternate use of docker run.
All right, now one last thing I wanna cover
in the next section, so quick break
and I'll see you in just a minute.