Sunday 9 June 2019

Tagging a docker image

In this article we will see how to tag an image in docker.

Docker Image Tag background

Tagging an image gives docker image a version to refer from local repository or docker hub. Though optional, it is highly recommended to have a tag for an image. If you look at the docker image its naming looks like: username/repository:tag


Different ways to tag a docker image
Different ways to tag a docker image


Command to tag an image

There are multiple ways we can tag a docker image. Here are the ways to tag a docker image:

(a) Tagging an image during image creation: 

We can create a tag or multiple tags during image creation. The only limitation is that the docker version should be 1.10 or above. The command is:

docker build -t name1:tag1 -t name2:tag2 -t name2:tag3
    

(b) Tagging an image using image:

Using tag command, we can tag an existing image. There are 2 ways to do that. Using image id or using image name

docker tag myimage tech693/myimage:1.0
    

This will create another copy of image with name "tech693/myimage" with tag "1.0"

Deleting a docker Image

So well you have created image but now want to delete it. docker rmi command is used to delete the image

docker rmi <imagename:tag>

How to rename docker image

Renaming docker image is easy but bit tricky. The idea here is to create another image with tag and delete the older one.

Example

docker tag <oldImage:tag> <newImage:tag>
docker rmi <oldImage:tag>

You will notice that if you tag same docker image with multiple name, its Image id remains same which mean tagging is just a name to refer the Image Id for human readability purpose.

That's all about tagging a docker image. If you have query, please ask in comment section. Thanks


Related Articles:
You may also like:

No comments:

Post a Comment