[docker] create multiple tag docker image

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

This question is related to docker

The answer is


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.


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


docker build  -t name1:tag1 -t name2:tag2 -f Dockerfile.ui .