- [Instructor] To display detailed information
on an image you can use the docker image inspect command
or just docker inspect.
The docker documentation has some great reference material
on exactly how to use this command,
as well as how to use the formatting
and filtering options for it.
Of course it's important to know how to filter the output
because the output from the docker image inspect command
can be rather lengthy.
Not only can you use docker image inspect,
but you can also use docker inspect.
If we go down here, while docker does recommend
docker image inspect, the docker documentation
for docker inspect has a number of extended examples
that talk about how to perform this type of filtering
that we'll be doing in this video.
So if you're looking for examples on how to format output
I'm going to show you some here in just a moment.
But there's also some great examples here
in the docker documentation underneath docker inspect,
not just docker image inspect.
So make sure that you check that out.
So now let's go over into the command line
and let's perform some of our own filtering and formatting
with docker image inspect.
If we run docker image ls you can see we have
a couple of images out here, so let's go ahead
and do a docker image inspect on the ubuntu
call in latest image.
As you can see we get a long list of output right there.
Of course we can do an up arrow and we can do a pipe
and pipe that to more, that's no problem.
And we've analyzed this before in this course
looking for when the image was created, the repo tags,
basically the tags that this image has applied to it,
the host name of the image, the environment path
that will be used when this image is instantiated
into a container, the full image ID, any volumes,
working directory, the version of docker this image
was created with, the type of operating system inside,
the size of the image, and the layers that
make up this image.
So all of this is visible here with
the docker image inspect command.
And it's actually in a nice outline format in sections,
and it's formatted in what they call a json array.
So it's kinda like a key value store if you will.
But if we wanna filter this output of course we could use
more like Linux filtering tools, like we could pipe
that output and we could use something like grep
and we could grep for OS to get the OS of the image.
We could of course redirect this output to a file
if we wanted to do that.
Let's call it ubuntu inspect dot text,
and then we could if we clear the screen,
we could do a nano on ubuntu inspect dot text.
And then we could edit this basically in a text editor
so that we could scroll up and down easily.
We could do some searching if we wanted to do that.
So just a few ways to filter the output,
but if we want to use the docker image inspect command
to format the output and essentially filtering it for us,
we've got a few different ways to do it.
So again, let's try docker image inspect
on the ubuntu image.
And if we just press enter on that,
of course we get our long output.
If we do a dash, help, oh sorry a dash dash help,
it tells us that we can use the dash F
or dash dash format to format the output.
So let's go ahead and try that.
I'll clear the screen here,
so if we do a docker image inspect
and the image is ubuntu colon latest,
and how this format option works is if we do
a dash dash format equals single quote
and then two squiggly brackets, we can do something like
dot ID, for the container ID,
end it with two squiggly brackets and a single quote,
and there we go.
See how it starts with four five two after the sha256,
after the sha256 indicator starts with four five two.
If we do a docker image ls, there you can see our image ID
is starting with four five two.
So we pulled out the image ID using the
docker inspect command with the dash dash format option
by specifying just the ID that we wanted to pull out.
So if we clear the screen
and let's do a docker image inspect on ubuntu colon latest
again, we'll pipe that to more,
and let's say that we wanna take a look at
the container config.
So we have this section here called container config,
and in the container config we have for example
the host name that will be created for this container
once it's instantiated from this image.
So if we wanted to pull this out using the format option,
I'm just gonna do an up arrow because this is
a rather long command here, and if we just wanted to
pull out let's say the container config,
we get an output of just the values of that
container config section.
So notice the host name is right here,
the very first value.
But what if we actually want the key and value pairs.
If we do an up arrow here you can do an option
where you say you want json output right there,
and let's try that again.
And now we get see the key and then the value
that goes along with that.
So host name and value.
But what if we just wanted the host name?
If we clear the screen here, let's do an up arrow
since this is rather long again.
And so if we just wanted the host name value
we can say we want the container config
and then we want dot host name,
and there, we were able to pull up only the host name
of what will become the container from this image
using the docker image inspect command with
the dash dash format option.
You can also do some other cool things like ranges
where you say you want a range from for example,
networks all the way down to the end of IP address
in that section, you can specify a range out of a section.
And then of course you can combine this even
with other Linux or Windows scripting tools
to filter out specific values.
So you have a lot of options here,
and keep in mind that everything that you learned here
about inspecting images also applies
to inspecting containers because the docker inspect command
can really inspect containers, images and much more.