- [Narrator] Docker relies on tags to identify
exactly what images are. Now, you shouldn't use
tags like you use tags on, for example, a file
in an operating system, for example tagging it
a document,
or Linux,
or a spreadsheet, something like that.
Tags don't work that way in docker.
In docker, tags should be used to identify
the version of, for example, the operating system
or the version of the application that you've
built with a docker file. So, you can use the
docker tag command, if you'd like to, and the
docker documentation has a number of examples
in the docker tag command, on exactly how you
can use it. Essentially, the format is: docker,
tag, space, and then
the source,
with the colon tag,
and the target image, with colon tag.
However, docker recommends that you instead use
docker, image, tag. So, if we go over to the
docker image tag documentation,
you'll see it
says it uses the exact same format, but, we
don't have any examples here, of exactly how
to use it. So, that's why I started off by
showing you the docker tag command.
So, let's go to the command line, and I'll
show you exactly how to use
docker image tag.
If we do a docker image ls, you can see we
have a couple of images available to us.
One is named "ubuntu," with a tag of "latest,"
and the other has no name, and no tag.
It just has an image ID.
So, it would be good, first, to tag this
image ID out here that has no tag at all.
So, let's do the docker image tag command,
and then the source, name, and tag, aren't going
to work for this image. Instead, we're going
to have to use the image ID, and then we're going
to do a destination name and tag after that.
So, let's just call this "my app, colon, latest."
So, we'll do a docker image ls, again.
And there we go. We have my app, with the latest
tag on it. So, we tagged this image that did not
have any tag at all.
Now, tags are essentially aliases.
So, an image can have not just one tag, but
multiple tags, but all point back to the same
source image.
For example, let's say that we wanted to do
a docker image tag, and take my app colon latest,
use that as the source, and also call it
"my app, colon,
original."
Something like that.
So, let's do a docker image ls, and now notice
we have my app out here twice, but we have two
different tags: latest, and original.
But notice here how they point back to the exact
same image ID.
So, it's the same image, but it has multiple
tags, and you can do this, really, virtually
an unlimited number of times, but, obviously,
you only want to do it when you have a specific
use case.
While you can use whatever names and tags that
you would like locally, if you wanted to push
an image up to a public repository, or even to
a private repository, you're going to need to
use a naming convention, with a slash, typically.
For example, if we clear the screen, let's say
that we want to push the ubuntu image up to
docker hub, which is the default repository for
docker. So, we'll use the docker image tag
command, and we'll call ubuntu image,
we'll tag it
with the name
of my
docker
hub
repository login,
slash, and then I can call it ubuntu,
colon,
David,
or, ubuntu, colon, latest,
whatever we'd like to use for the tag.
And, then, in a future video, I'll show you
exactly how to push that image up to a
public repository.
But if we do a docker image ls here, you can
see, now, the name of this image is
"David Davis tx," which is my docker hub
username, "slash ubuntu," with the "latest" tag.
So, that's what you need to know about using
image tagging in docker.