‫Requirements for this lecture include knowing the basics about what a container and an image are in
‫Docker and understanding the layers,
‫or at least the basics of layers. Know a few things about Docker Hub.
‫This lecture is going to be all about image tags and how to upload them to Docker Hub.
‫There's actually a lot to tags because they're not as intuitive as you might think when you first
‫start using them. They need to actually be in a specific format in order to work with a registry,
‫specifically with Docker Hub. Then I'll talk to you about the relationship between the tags that are
‫assigned to your images and the IDs of those images.
‫So let's get started.
‫First let's talk about tagging. docker image tag --help. Images don't technically have a name even
‫though we kind of refer to them like that when we're talking casually.
‫If we do a docker image ls,
‫you notice that there's no name column.
‫Besides the image ID, which none of us are going to remember those right?
‫We have to refer to them by three different pieces of information.
‫On this screen for the image ls command, we actually only see two of them. Over on the left,
‫we're seeing the repository,
‫then we're seeing the tag. The repository is actually made up of either the user name or the
‫organization slash the repository.
‫Here we're only dealing with official repository images
‫so we're only going to see the actual repository name.
‫We mentioned earlier that the special images that are considered official are the only ones that
‫get the right to just be called their name of the repository, not the actual name of the organization
‫slash repository.
‫But if we go over to Docker Hub, and I just do a search on mysql, we'll find that there's actually an
‫organization, not only just the official mysql, which is just referred to as mysql, but there is
‫the SQL organization with a mysql-server, which seems to be pretty popular as, well, it's got
‫over a million downloads. It looks like what it is here is this is actually the same MySQL server
‫but it's actually created by the MySQL team at Oracle.
‫If I actually wanted to download it, you'll notice here on the right,
‫I have to do a docker pull mysql/mysql-server. I can actually click the copy button and
‫I copy this in. It will actually download this unique organizational-based image and if I do a docker
‫image ls again, you'll notice that the repository name includes the organization name.
‫On my account on Docker Hub, I'm known as bretfisher. You can see it from the top right.
‫So if I were to look at my dashboard and look at my images that I have that are public,
‫for example, let's look at the nodemongoapp.
‫If you were to download this, I would need to do
‫docker pull bretfisher/nodemongoapp.
‫Now that we understand how the repository is named what does the tag for?
‫The tag is not quite a version and it's not quite a branch, but it is a lot like Git tags.
‫So it's kind of a little bit of both.
‫It's really just a pointer to a specific image commit, and really could be anything, into that repository.
‫If we went back to Docker Hub for a minute, and we went up to mysql official image, you'll see on the
‫front page it has these different tags. What they're trying to say here is that the 8.0.0 and the
‫8.0 and the 8 are all tags for the same image ID.
‫If I scroll up here and look at the tags button, I get a full detailed list of all the various tags
‫that they've given to the mysql.
‫So let's go to Nginx, which is what we've been working on a lot.
‫We'll see in here that it isn't just numbers but it's actually names as well.
‫It's important to point out that these are actually all the exact same image and Docker's smart enough
‫to know that. I go to my command line and I see that I already have the nginx latest downloaded.
‫If I looked at the web page, I see the latest tag right here but it's also called mainline.
‫So what if I did a docker pull nginx:mainline? What this is telling us is it actually already
‫knew that based on the image ID, this image is already in my cache. Now if I do a docker image
‫ls again, I'll see two different nginx. You'll notice that they have the exact same image ID because
‫they're not really stored twice in the cache and, again, this goes back to a lot of the savings. These
‫tags are just labels that point to an actual image ID and we can have many of them all point to the same
‫one.
‫So how do I make new labels?
‫Well I could make my own Dockerfile and create my own custom image, but we can also re-tag existing Docker
‫images so I can just do a docker image tag nginx
‫bretfisher/nginx. The format of this command is the image that I'm going to give a new tag
‫to goes first, and then the new tag that I want to give it.
‫If I did a docker image tag --help again, just to refresh your memory, it shows the SOURCE_IMAGE and an
‫optional tag
‫and then the NEW_IMAGE an optional tag.
‫So if you don't specify the tag, it'll always default to latest. Latest doesn't actually always mean
‫latest because I technically could take some old software and tag it latest.
‫There's nothing special about it but it is just kind of the default. Really,
‫I wish they would just call it default and not latest.
‫So it is a little confusing,
‫but generally on Docker Hub, especially when you're using official images, you can trust that the latest
‫is generally the latest stable version of the software that you want to use.
‫So let's do a docker image ls
‫again. Notice what's happened.
‫I have added a new tag to an existing image that I didn't make.
‫It shows the same image ID
‫and now it's labeled with my user name and a new repo that doesn't exist yet on Docker Hub.
‫If we went and looked at my dashboard,
‫I don't have anything called bretfisher/nginx.
‫So what if I did a docker image push, similar to like a Git push, bretfisher/nginx?
‫denied: requested access to the resource is denied.
‫So it clearly tried to upload what I just created, it tried to upload that tag, but it gave me access
‫denied.
‫That's because I haven't actually logged in.
‫So if you look at the docker --help you'll see a login and logout command. We haven't used those yet.
‫So once you have your own free Docker Hub account, you can actually login from the command line docker login.
‫...
‫So what this actually did was there was this wrote to a file, that by default is in my profile under cat .docker/config.json,
‫and it actually stored an authentication key that would allow my local docker CLI to access
‫Docker Hub as me.
‫This is an important point that we'll learn about later on in production is that wherever you login
‫with the Docker CLI, by default, it's going to store this authentication key for your account in the
‫profile of that user.
‫So just be aware of that.
‫If you're using a machine that you don't trust, when you're done just type docker logout.
‫So now that we're logged in, I'm going to hit the up arrow to try to push that image again.
‫OK.
‫So it seems like it's done.
‫Let's go over to Docker Hub and hit refresh. There it is,
‫bretfisher/nginx. Again, I didn't actually have to create this from scratch to upload
‫it.
‫I just simply gave a new tag to an existing image and when I uploaded it, it automatically created a
‫new repo based on that tag.
‫Of course I could fill out all the information here, and you'll see that it defaulted to the latest
‫tag name because I didn't specify one. So I could actually go back and do the up arrow thing until I
‫get to my tag and I could actually give it a different tag.
‫We're going to add an additional tag to that same image and I'm going to call it testing. If we do a
‫docker image ls,
‫you'll see that I now have three all with the same image ID.
‫If I did a docker image push bretfisher/nginx:testing, and this time I specified testing,
‫notice how it says layers already exist.
‫That's part of our awesome savings rate.
‫When we're downloading and uploading images, that there's already layers that exist, it won't bother
‫re-uploading them.
‫If we go back and I hit refresh, you'll see that I now have another tag.
‫But of course if I just did a docker image ls, we see just like we saw that it's the same image ID and
‫both sides of this connection know it. If I wanted this to be a private repository, because that is
‫a supported feature of Docker Hub, what I'd probably want to do is create the repository first, and when
‫I created it, I specified for it to be private.
‫Then when I pushed to it, the code would never be publicly on the Internet.
‫Wow, there's a lot to images and their tags.
‫So let's just do a quick review.
‫As you can see, you can pretty much tag anything on to images but they have to be in a specific format
‫to work with Docker Hub. You can't just call something nginx and then upload it because it's
‫not going to work unless it has your account ID or organization ID in the front of it.
‫Then I talked about how you can actually have many tags for the same image ID and just because you
‫re-tag or tag differently an existing image, it doesn't actually change that image ID.
‫Remember that the latest tag is really just the default tag.
‫There's nothing inherently special about it, but we do kind of assume on Docker Hub, it is pretty
‫much a standard there, that people use the latest tag as a way to indicate the latest stable version
‫of their image. I showed you how to quickly login and out of Docker Hub from the CLI. Remember
‫that that stores a session ID in your local config if you're on a Linux machine and you make sure that
‫you logout to remove that
‫if you're on a shared Linux machine or a host, like a server. Then, just a reminder, if you want to
‫create a private Docker Hub image, you should probably create the repository first before you upload
‫it.