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 image
  • nginx is shorthand for nginx:latest when no tag is given
  • latest just means "default tag" — on official repos it's usually the newest stable, but anyone can stamp latest on 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.