How to create named and latest tag in Docker?
Supposed I have an image that I want to tag as 0.10.24
(in my case it's an image containing Node.js 0.10.24). I built that image using a Dockerfile and executing docker build
and by providing a tag using the -t
parameter.
I expect that one day I will have additional versions of that image, so I will rerun the process, just with another tag name.
So far, so good. This works great and fine and all is well.
But, and this is where problems start, I also want to always have the newest image tagged ad latest
additionally. So I guess I need to give two names to the very same image.
How do I do this? Do I really need to re-run docker build
on the exact same version again, but this time use another tag, is is there a better option?
Solution 1:
You can have multiple tags when building the image:
$ docker build -t whenry/fedora-jboss:latest -t whenry/fedora-jboss:v2.1 .
Reference: https://docs.docker.com/engine/reference/commandline/build/#tag-image-t
Solution 2:
Once you have your image, you can use
$ docker tag <image> <newName>/<repoName>:<tagName>
-
Build and tag the image with creack/node:latest
$ ID=$(docker build -q -t creack/node .)
-
Add a new tag
$ docker tag $ID creack/node:0.10.24
-
You can use this and skip the -t part from build
$ docker tag $ID creack/node:latest