DOCKER - 4 4 Image tags
Prerequisites for this lesson: you should already understand the basics of containers, images and at least a sense of how image layers work, plus have used Docker Hub a little. The focus today is tags — how to read them, how to create them, and how to push tagged images to a registry. Tags trip people up because they aren't quite what you think when you first meet them.
Tags are labels, not names
Images technically don't have names. docker image ls doesn't even have a "name" column — only a repository plus a tag, alongside the real image ID. The full reference takes the form <user-or-org>/<repo>:<tag>. Official images skip the user/org prefix (so it's just nginx, mysql, etc.). Visit MySQL on Docker Hub and you'll see things like 8.0.29, 8.0, 8, oracle — many of those refer to the same image ID, just labelled differently for convenience. For Nginx the same is true: you'll find numeric tags (1.21.6), Alpine-based variants (alpine) and aliases like mainline or latest.
Pulling a tag you already have caches a single physical image: if nginx:latest and nginx:mainline resolve to the same ID, docker image ls shows two lines but they share storage. That's the whole point of tags — they're labels pointing to image IDs, and many tags can point to the same one.
docker image tag <source> <target>— add a new tag to an existing imagenginxis shorthand fornginx:latestwhen no tag is givenlatestjust means "default tag" — on official repos it's usually the newest stable, but anyone can stamplateston anything
To add your own tag, use docker image tag with the source image and the new label, for example docker image tag nginx myaccount/my-nginx:latest. Re-run docker image ls and you'll see two entries with the same image ID. From there, docker push myaccount/my-nginx uploads it to Docker Hub under a brand-new repository linked to your account.
Summary
This lesson explains Docker image tags and their functionality. Tags are human-readable labels that point to specific image IDs, allowing users to reference images without memorizing long hash identifiers. Multiple tags can reference the same image ID, which saves storage space. The lesson uses official repositories like MySQL and nginx as examples to demonstrate how tags work and introduces the "docker tag" command for creating new tags on existing images.
Key points
- Image tags are labels that point to a specific image ID—technically, images are identified only by their hash, but tags provide user-friendly references
- Tags follow the format: repository:tag (e.g., 'nginx:latest', 'mysql:8.0'), where official images can use short names while user images require username/repository:tag format
- Multiple tags can reference the same image ID without creating duplicate images—tags are just aliases pointing to the same underlying image
- The 'latest' tag is the default when no tag is specified, though it does not always represent the newest version unless enforced by the repository maintainer
- New tags are created using the 'docker tag' command with the syntax: docker tag source-image new-tag, allowing images to be referenced by multiple names
- Official Docker images on Docker Hub typically assign multiple version tags to the same image ID for flexibility and backward compatibility
FAQ
What is the relationship between image tags and image IDs?
Tags are labels or aliases that point to a specific image ID. Multiple tags can reference the same underlying image ID without creating duplicate copies. Tags are just a human-readable naming convention for identifying images.
How do you create a new tag for an existing image?
Use the 'docker tag' command with the format: docker tag source-image new-tag, where source-image is the existing image ID or tag, and new-tag is the new label you want to assign to it.
Does the 'latest' tag always represent the most recent version?
Not necessarily—the 'latest' tag is just a label that can be applied to any image. However, for official Docker images on Docker Hub, the 'latest' tag is generally the most recent stable release of the software.