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?
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 .
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.
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With