Is it possible for image to have multiple tags?

DockerDockerhub

Docker Problem Overview


When I am pushing new image to repo I would like it to have two tags for example 0.2 and latest. This would allow to always pull latest image version by using latest tag and a specific version by using 0.2 tag for example. Is it possible with docker?

Is there any workaround? The only solution I see is to make two separate pushes...

Docker Solutions


Solution 1 - Docker

You can build an image with several tags and then push the image with the --all-tags option.

Example:

docker build -t reg/user/image:foo -t reg/user/image:latest .

docker push reg/user/image --all-tags

Older Docker clients that do not support --all-tags will push all tags by default (simply omit the option), newer clients will only push latest by default. As an alternative, you may want to push each tag separately.

Solution 2 - Docker

You can create multiple tags:

docker tag <id> <user>/<image>:0.2
docker tag <id> <user>/<image>:latest

and push these.

Solution 3 - Docker

You need to do one push per each version like:

docker tag test:latest <repo>/<user>/test:latest
docker push <repo>/<user>/test:latest

docker tag test:0.2 <repo>/<user>/test:0.2
docker push <repo>/<user>/test:0.2

You can also combine and say the latest version is 0.2 like:

docker tag <repo>/<user>/test:latest <repo>/<user>/test:0.2
docker push <repo>/<user>/test:0.2

So those will point the same image layer.

Solution 4 - Docker

UPDATE: Prior to Jan 2021

It pushes all the tags, if you dont specify the tags in push command.

docker tag user/imagename:tag1
docker tag user/imagename:tag2

docker push user/imagename

Solution 5 - Docker

There are valid reasons for having multiple tags on an image (see OP) but if you are wanting to add tags for informational purposes, you may be better off with image labels.

Docker labels are inside the image rather than applied to it in the registry. This means the labels are immutable and always get copied with the image.

Label Schema defines a list of interoperable labels for things like version, vcs-ref, build-date and others.

Solution 6 - Docker

If you don't want to refer the image by hash, but "copy a tag" you can do the following:

docker tag image:origin_tag image:target_tag
docker push image:target_tag

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser606521View Question on Stackoverflow
Solution 1 - DockerPeterinoView Answer on Stackoverflow
Solution 2 - DockermanojldsView Answer on Stackoverflow
Solution 3 - DockerHenrik SachseView Answer on Stackoverflow
Solution 4 - DockerAziz ZoaibView Answer on Stackoverflow
Solution 5 - DockerTamlynView Answer on Stackoverflow
Solution 6 - DockerlauksasView Answer on Stackoverflow