In this section we're going to continue looking at the darker run command or some slight variations
of it.
Now before I show you the next kind of variations command that we're going to look at I want to 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 going to give you a way to override this
default startup command here's how we do it will 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 going to execute Docker run and I'm going to specify my image.
We're going to use a different image than what we used before.
We're going to use an image called Busy Box.
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 going to say that I want to run a command echo Hi there so this right here is the override.
This is a command they'll be executed inside that container.
The Echo command is going to print out.
Hi.
Inside my terminal.
So if this works the way we would expect I'll see the text high there appear.
So going to 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 by there or I could say how are you.
You get the idea now.
I want to 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 Tex
back over to you.
I want you to run Docker run busy box and then the override command that we're going to use this time
is going to be less if you never used Alice before it's going to 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 been at sea Dev home proc Root says temp user ID 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 want to remind you about exactly what happens when we create a container out of an image.
So over here we've got the busy box image.
It has some default files 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
that busy box image has default folders of bin Dev Etsy home proc route and so on all the ones 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 less.
So we list out all the files and folders inside of our hard drive which then prints out bin Dev at the
home proc and root so that's pretty much it.
Now one thing you might be all a bit curious about is why we chose to use the busy box 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.
We're going to try running hello world with the LDS command so I'll do Docker run Hello dash world and
I'll do El s 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 Ellis commands with busy box those commands
work because Ellis and Echo are two programs that exist inside of the busy box file system image somewhere
inside of this folder system right here is a Ellis command or an actual LDS executable and a echo executable
as well.
And so we can safely execute those commands with busy box 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 include with the
image.
And if we tried to execute a command inside the container that uses a program that doesn't or is not
contained within this file system we're going to see that error.
OK.
So a little bit more on Docker on command.
Let's take another quick break right now and continue in the next section.