Docker tag command

Docker command reference


docker tagThe command is used to create an alias (tag) for a local image. By tagging an image, you can use easier-to-remember names or version numbers to identify and manage the image.

Syntax

docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
  • SOURCE_IMAGE[:TAG]: Source image name and tag, tag defaults tolatest。
  • TARGET_IMAGE[:TAG]: Target image name and tag, tag defaults tolatest。

1. Tag the image

docker tag myimage:1.0 myrepo/myimage:latest

This will tag the local myimage:1.0 image as myrepo/myimage:latest.

2. Add multiple tags to the image

docker tag myimage:1.0 myrepo/myimage:stable
docker tag myimage:1.0 myrepo/myimage:v1.0

This will tag myimage:1.0 as myrepo/myimage:stable and myrepo/myimage:v1.0 respectively.

3. Tag the image to push it to Docker Hub

docker tag myimage:1.0 myusername/myimage:1.0
docker push myusername/myimage:1.0

This will tag the myimage:1.0 image as myusername/myimage:1.0 and push it to Docker Hub.


Example

Tag the image

1. List local images

docker images
REPOSITORY          TAG       IMAGE ID       CREATED        SIZE
myimage             1.0       123456789abc   2 days ago     500MB

2. Tag the image

docker tag myimage:1.0 myrepo/myimage:latest

3. Verify the tag

docker images

Output example:

REPOSITORY          TAG       IMAGE ID       CREATED        SIZE
myimage             1.0       123456789abc   2 days ago     500MB
myrepo/myimage      latest    123456789abc   2 days ago     500MB

Notes

  • A tag is just an alias for the image; it does not create new image layers, so it does not take up additional storage space.
  • Tags should be concise and descriptive, making it easier to identify and manage image versions.
  • When using tags, ensure the naming complies with the registry's naming conventions.

docker tagThe command is an important tool for managing Docker images. By tagging images, you can conveniently identify, manage, and publish different versions of images. This command is suitable for various scenarios, including version management, image publishing, and image replication. When using it, ensure that tag naming is standardized and descriptive to improve the efficiency and maintainability of image management.


Docker command reference

other extensions