Docker Tag Command Tutorial

The docker tag command is used to manage tags for the docker images. An image consists of multiple layers which can be derived by new other docker images. Tags are used to identify and track different images easily. Tags names should only use ASCII characters. The tags are registered the registry-1.docker.io in order to be accessible to others and easily downloaded.

Docker Tag Command Syntax

docker tag SOURCE_NAME:TAG TARGET_NAME:TAG
  • SOURCE_NAME is the source image name that is tagged with the TARGET_NAME. The TAG is optional.
  • TARGET_NAME is the new name with the TAG.

List Images with Tags

Before starting to tagging images with tags listing the images and related tags is very useful. The docker images command can be used to tag images.

$ docker images
List Images with Tags

Tag Existing Image with New Tag

We start with a simple example where we tag an existing image with a new tag and new image is created and listed in the docker images. The source and destination image names are provided with tags. In this example we tag existing ubuntu image as myubuntu name.

$ docker tag ubuntu myubuntu

And we can list the docker images like below. We can see that the new docker image named myubuntu is created in the registry.

$ docker images

Tag Existing Image+Tag with New Tag

The latest tag is used by default in order to search, pull or tag images. In the previous example, we can see that the newly named image has the latest tag implicitly. We can explicitly specify new tag during tagging. In the following example we use tag named nginx .

$ docker tag ubuntu myubuntu:nginx

Tag Image Referenced By ID

An image can be tagged by using its ID. Every image has its own unique ID in order to identify uniquely. Even names that provide human-friendly usage IDs can be used to specify images more strictly. The syntax of the tagging using ID.

docker tag ID TARGET_NAME:TAG
  • ID is the source image id.
  • TARGET_NAME is new image name.
  • TAG is the TARGET_NAME tag.
$ docker tag 87eefc7c15610cca61db5c0fd280  myubuntu:nginx

Tag Image Referenced by Name and Tag

We can tag an image by referencing both the image name and tag. For example, ubuntu may have multiple images with different tags. The syntax of tagging by referencing name and tag is like below.

docker tag SOURCE_NAME:TAG TARGET_NAME:TAG

In the following example, we tag the source image ubuntu with latest tag into new name and tag myubuntu:nginx .

$ docker tag ubuntu:latest myubuntu:nginx

Tag Image for Private Repository

Images can be also tagged and published into the private repository. The repository information is provided before the target name and tag like below.

See also  Linux chroot Command Tutorial

$ docker tag ubuntu:latest myprivaterepo.com:5000/myubuntu:nginx

Leave a Comment