Reputation: 1425
For instance, there is one repository created using
$ docker tag friendlyhello john/get-started:part1
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
friendlyhello latest d9e555c53008 3 minutes ago 195MB
john/get-started part1 d9e555c53008 3 minutes ago 195MB
Now here are two images: friendlyhello:latest
and john/get-started:part1
.
I noticed that these two images has the same IMAGE ID
.
So I guess there is just ONE image file on my disk.
If it is true, why should I tag to the repository just like create a link file in operating system?
Upvotes: 3
Views: 3525
Reputation: 3439
In short, tags are used for convenience in order to identify an image (which is a combination of filesystem layers). Because your image evolves over time and sees more layers being added to form a new image, tags are also a convenient way to do versioning.
When a user downloads your image from a registry like Docker Hub or the Google Container Registry, they can easily associate which version they are downloading from the tag.
It is no different than tagging a release with git if you are familiar with it but you are tracking changes to your image in this case. You tag a release for your image and push changes to your remote repository.
Taking Ubuntu as an example, tags are used to refer to specific releases of the operating system and there can be plenty. For example these are all valid tags for Ubuntu (see docker hub's page):
rolling
zesty
17.04
latest
xenial
16.04
trusty
14.04
Multiple tags can point to one container image. With Ubuntu: xenial
, latest
and 16.04
are tags that point to the same location, these are just many ways to refer to the same image. This way and because I know that the latest
(stable) version of Ubuntu is xenial
and the version number is 16.04
, I can download this specific image from the Docker Hub using either of these terms or tags.
In the same way trusty
and xenial
do not point to the same image. They point to images that may have common filesystem layers but diverged at some point.
Upvotes: 7
Reputation: 16305
You can tag images to make sure you will be able to find them later. If you store an image only with latest its probable you'll overwrite it on the next build and then potentially delete it with docker prune which deletes all images that are not referenced.a
Upvotes: 1