-: In this section, we're going to continue looking
at the docker run command or some slight variations of it.
Now, before I show you the next kind of variations command
that we're gonna look at,
I wanna give you one quick reminder.
Remember, any time that we execute docker run with an image,
we not only get that file system snapshot,
but we also get this default command
that is supposed to be executed
after the container is created.
So, the variation on docker run that we're gonna look at
is gonna give you a way to override
this default startup command.
Here's how we do it.
We'll execute docker run, the image name,
just like we did before,
and then after that we'll supply a alternate command
to be executed inside the container after it starts up.
This is an override.
So, whatever default command is included inside of the image
is not going to be executed.
Let's try this out right now and just see how it works.
All right, so I'm going to find my terminal
and I'm gonna execute docker run,
and now I'm going to specify my image.
We're gonna use a different image than what we used before.
We're gonna use an image called busybox,
and I'll tell you why in just a moment.
After that, we'll list out the alternate command
to execute inside the container after it is created.
And so, I'm gonna say that I want to run a command,
echo hi there.
So, this right here is the override.
This is a command that we executed inside that container.
The echo command is going to print out
"hi there" inside my terminal.
So, if this works the way we would expect
I'll see the text "hi there" appear.
So, I'm gonna run that and sure enough, yep, we see that.
We can change the text provided here
to the echo command as much as we please.
So I could say, "bye there," or I could say, "how are you?"
You get the idea.
Now, I wanna show you a small variation on that command,
and this is going to start to make things
a little bit more interesting
than just kind of echoing text back over to you.
I want you to run docker run, busybox,
and then the override command that we're gonna use this time
is going to be ls.
If you've never used ls before,
it's gonna print out all the files and folders
inside of a given directory.
So, let's try running this and see what happens.
So, according to our docker container,
when we print out our files and folders,
we have bin at C, dev, home, proc, root,
system, user and var.
These are all folders right here.
And, if you are on, say, a Windows machine right here,
these folders might look very strange to you
and very unfamiliar.
So, in fact, these are folders that are being printed out
that are not belonging to you on your computer.
These are folders that exist solely inside that container.
I wanna remind you about exactly what happens
when we create a container out of an image.
So, over here we've got the busybox image,
it has some default file system snapshot
and some presumably default command.
You know, who knows what it is off top of my head
but it definitely has this default file system snapshot.
The busybox image has default folders
of bin, dev, at C, home, proc, root, and so on.
All the ones that you see listed right here.
So, when we create a new container out of that image,
we take this file system snapshot,
we stick it in as the folder for that container,
and then the command that we execute is ls.
So we list out all the files and folders
inside of our hard drive,
which then prints out bin, dev, at C home, proc and route.
So, that's pretty much it.
Now, one thing you might be a little bit curious about
is why we chose to use the busybox image here
as opposed to the hello world one that we were using before.
Well, let's go back over to our terminal really quickly
and we're gonna try running hello world with the ls command.
So I'll do a docker run, hello dash world,
and I'll do ls right here.
And you're gonna very quickly
see that we get a kind of nasty error message.
Well, let's try doing the echo command and see what happens.
I'll do docker run, hello world, echo hi there,
and we get a very similar error message here as well.
So, what's going on?
Well, here's the issue.
When we run the alternate commands or those alternate echo
and ls commands with busybox,
those commands work
because ls and echo are two programs that exist
inside of the busybox file system image.
Somewhere inside of this folder system right here
is a ls command or an actual ls executable
and a echo executable as well.
And so we can safely execute those commands with busybox
because those are programs
that exist inside this file system.
However, with our hello world program over here,
the only thing that exists inside this file system snapshot
is a single program, like one single file
and all that thing does is echo out
or kind of print out that singular message
that we saw when we ran that container.
So, these startup commands that we are executing
are being based upon the file system
included with the image.
And if we try to execute a command inside the container
that uses a program that is not contained
within this file system, we're going to see that air.
Okay, so a little bit more on docker run command.
Let's take another quick break right now
and continue in the next section.