Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create named and latest tag in Docker?

Tags:

docker

tags

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?

like image 301
Golo Roden Avatar asked Feb 27 '14 21:02

Golo Roden


People also ask

How do I tag a docker image as latest?

Latest is Just a Tag It's just the tag which is applied to an image by default which does not have a tag. Those two commands will both result in a new image being created and tagged as :latest: # those two are the same: $ docker build -t company/image_name . $ docker build -t company/image_name:latest .

How do you name a docker tag?

A tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods and dashes. A tag name may not start with a period or a dash and may contain a maximum of 128 characters.

Does Docker automatically tag latest?

In reality, latest is used as the default tag when you haven't specified anything else. That's the only time it'll be used – it doesn't automatically refer to the newest image you've built. If you now ran docker run my-image:latest , you'd be using the second image to be built.

How do I create a tag in Docker Hub?

Docker Tag Command Here, the component after the colon specifies the tag given to the image. We can only specify tag names that contain valid ASCII characters only. However, they can contain digits, periods, underscores, dashes, and both lowercase and uppercase letters.


2 Answers

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

like image 104
Tommy Avatar answered Nov 05 '22 16:11

Tommy


Once you have your image, you can use

$ docker tag <image> <newName>/<repoName>:<tagName> 
  1. Build and tag the image with creack/node:latest

    $ ID=$(docker build -q -t creack/node .) 
  2. Add a new tag

    $ docker tag $ID creack/node:0.10.24 
  3. You can use this and skip the -t part from build

    $ docker tag $ID creack/node:latest 
like image 36
creack Avatar answered Nov 05 '22 18:11

creack