Now that we've had our warning about the Docker group,
we can use Docker however we want.
And we can begin by taking a look at Docker Images.
So we can go through and look at the docker image ‑‑help so
we can see the options are available, but we've also got tab completion as well.
We can list our images.
We can go through and inspect our images to read metadata.
If we're using ‑f we can then filter, and we can be looking then for repo tags.
We're going to be able to see the names that have been assigned to this image.
The image really is based around the image ID,
but we can give human‑readable tags.
The tag that will exist will be hello‑world, but I can add additional tags.
So here we're adding in the my‑hello tag to hello‑world.
Again,
we can go through and look at the image ls and we'll see
both the my‑hello and hello‑world images.
When we go through and take a look though,
if we search on the image id, the image exists just as a single file,
but we have multiple tags assigned to it.
We can also go through and search for images.
If we want to look for our Ubuntu images,
we can then go through and search for ubuntu.
If we add in the filter, is‑official=true,
we'll only see those officially supported images.
Now looking at these and other commands,
we can move out to our command line now and take a look at how
we work with the docker command and images.
Our real fun with Docker starts with images.
Images only need to be downloaded once and can be
used multiple times for containers.
Containers are runtime representation of our images,
and we can have many containers based on the one image.
Now we can use then the id command,
and we can see with the id command that I'm
currently belonging to the Docker group.
So why don't we just make use of the Docker group,
and I can run the docker command without the sudo command?
I'm not going to be doing anything dangerous.
Now I can use the docker images command or the docker image subcommand.
When I look at docker images, it will list all of my images,
but in later versions, things have been tidied up a little bit.
So we've got the image subcommand and the ls subcommand to this,
so we're grouping commands together.
If I go back to Docker image and Tab, Tab,
double‑Tab on this,
I'm able to see all of the subcommands that are related to docker image.
And say, in this way,
we can kind of group everything together and it
becomes a little bit more logical.
So either way,
we can use the old school way of doing it with
docker images or docker image and ls.
The docker image inspect command is used to look at the metadata,
the system information about an image, and if we look at then the hello‑world,
we can use tab completion on our image name as well,
then we get to see everything in our metadata.
Now this is okay,
but we might prefer to filter on certain information
if we know what we're looking for.
So if I go through and add in the inspect and ‑f for filter,
and then quote and my double‑brace brackets,
I can look for .RepoTags,
so we're looking them for a subkey called RepoTags inside of our metadata,
and we can see there that we've got the one tag,
hello‑world and latest.
Latest just being the version.
Now the idea of a tag is that we're giving a
human‑readable name through to the image.
I can add as many tags as I want, so I can retag hello‑world to be my‑hello,
and then if I go through and look at my image and ls,
I'm going to see both images, so both the hello‑world and the my‑hello.
But if you look at the image ID, it's exactly the same image ID.
The real name is the image ID,
and we see just the first few letters of the image ID.
By searching the file system with the find command,
and our images are going to be in var, lib,
and docker, we can search for the image ID as a name.
So if you cut that and get ready to paste the image ID in,
we can say our name and then the image ID with an asterisk,
don't forget the asterisk.
Now we're getting permission denied,
so you can see as a standard user even in the docker group we don't get right,
but sudo!! runs the same find command, and we're able to see then that we've
got two results coming back, both as content and metadata.
The actual image file is under the content subdirectory.
If we want to gain other images or download other images,
we could go through and do a docker search.
Here we're searching for ubuntu, and we get a lot coming back.
If we want to then filter a little bit more,
we might only want those official images,
so we can use ‑f for filter, is‑official,
and then =true, and we get a smaller list coming back.
A lot is looking at the number of stars that have been associated and
that gives you an idea of how good the image might be.
If I go through and change say ubuntu to centos,
this will be the latest CentOS version.
If I wanted to, I could pull this down, so I could use a docker image,
and pull, and centos,
so we can then have it ready before I create a container from it.
Once we've got this image down, it will be the latest CentOS image,
but if I wanted a different CentOS image,
then I could put the version on the end.
So if I put centos:7, it then pulls down the CentOS 7 image,
and we will have both the CentOS latest,
so that's going to be CentOS 8, and the CentOS 7.
So if I go back now to my docker image, or images,
I could use either, and we can see now that I've got the ubuntu,
hello‑world, my‑hello, centos 7, and centos latest.
And it's only the hello‑world and my‑hello that have the same image ID, so
we can work out which images are just additional tags.
But give yourself a big pat on the back,
you've become a little bit more familiar with working with the
docker image subcommand and managing your images,
your all‑important images,
which are the foundation stones for creating your containers. We'll look at managing containers, next.