create multiple tag docker image

Docker

Docker Problem Overview


How can several tags be attached to one Docker image? Is it possible to create multiple tags using one Dockerfile?

It is possible, somehow; for example docker pull ubuntu will get several images, some of which have multiple tags:

ubuntu                  13.10               9f676bd305a4        2 weeks ago         182.1 MB
ubuntu                  saucy               9f676bd305a4        2 weeks ago         182.1 MB
ubuntu                  raring              eb601b8965b8        2 weeks ago         170.2 MB
ubuntu                  13.04               eb601b8965b8        2 weeks ago         170.2 MB
ubuntu                  12.10               5ac751e8d623        2 weeks ago         161.4 MB
ubuntu                  quantal             5ac751e8d623        2 weeks ago         161.4 MB
ubuntu                  10.04               9cc9ea5ea540        2 weeks ago         183 MB
ubuntu                  lucid               9cc9ea5ea540        2 weeks ago         183 MB
ubuntu                  12.04               9cd978db300e        2 weeks ago         204.7 MB
ubuntu                  latest              9cd978db300e        2 weeks ago         204.7 MB
ubuntu                  precise             9cd978db300e        2 weeks ago         204.7 MB

Docker Solutions


Solution 1 - Docker

Since 1.10 release, you can now add multiple tags at once on build:

docker build -t name1:tag1 -t name1:tag2 -t name2 .

Source: Add ability to add multiple tags with docker build

Official Docker doc: https://docs.docker.com/engine/reference/commandline/build/#tag-an-image--t

Solution 2 - Docker

You can't create tags with Dockerfiles but you can create multiple tags on your images via the command line.

Use this to list your image ids:

$ docker images

Then tag away:

$ docker tag 9f676bd305a4 ubuntu:13.10
$ docker tag 9f676bd305a4 ubuntu:saucy
$ docker tag eb601b8965b8 ubuntu:raring
...

Solution 3 - Docker

How not to do it:

When building an image, you could also tag it this way.

docker build -t ubuntu:14.04 .

Then you build it again with another tag:

docker build -t ubuntu:latest .

If your Dockerfile makes good use of the cache, the same image should come out, and it effectively does the same as retagging the same image. If you do docker images then you will see that they have the same ID.

There's probably a case where this goes wrong though... But like @david-braun said, you can't create tags with Dockerfiles themselves, just with the docker command.

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
QuestionDaniel YC LinView Question on Stackoverflow
Solution 1 - DockerMarc Perrin-PelletierView Answer on Stackoverflow
Solution 2 - DockerDavid BraunView Answer on Stackoverflow
Solution 3 - DockercassavaView Answer on Stackoverflow