create multiple tag docker image

2019-01-22 16:52发布

问题:

docker pull ubuntu will get a multiple tags images.

Is it possible to create multiple tags by one Dockerfile like the ubuntu?

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

Here, what I required is the tags for different content. (Not the same content with multiple alias tags)

回答1:

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
...


回答2:

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



回答3:

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.



标签: docker