Docker tag command
docker tag The 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 images.
Syntax
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
SOURCE_IMAGE[:TAG]: Source image name and tag; the tag defaults tolatest。TARGET_IMAGE[:TAG]: Target image name and tag; the tag defaults tolatest。
** 1. Tag an image**
docker tag myimage:1.0 myrepo/myimage:latest
This marks the local myimage:1.0 image as myrepo/myimage:latest.
** 2. Add multiple tags to an image**
docker tag myimage:1.0 myrepo/myimage:stable
docker tag myimage:1.0 myrepo/myimage:v1.0
This marks myimage:1.0 as myrepo/myimage:stable and myrepo/myimage:v1.0 respectively.
** 3. Tag an image to push it to Docker Hub**
docker tag myimage:1.0 myusername/myimage:1.0
docker push myusername/myimage:1.0
This marks the myimage:1.0 image as myusername/myimage:1.0 and pushes it to Docker Hub.
Example
Tag an image
1. List local images
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
myimage 1.0 123456789abc 2 days ago 500MB
2. Tag an image
docker tag myimage:1.0 myrepo/myimage:latest
3. Verify the tag
docker images
Example output:
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 an image; it does not create a new image layer, so it does not take up extra storage space.
- Tags should be concise and descriptive, so that image versions are easy to identify and manage.
- When using tags, make sure the naming follows the registry's naming conventions.
docker tag The command is an important tool for managing Docker images; by tagging images, you can easily identify, manage, and publish different versions of images. This command applies to a variety of scenarios, including version management, image publishing, and image replication. When using it, ensure tag names are standard and descriptive, to improve the efficiency and maintainability of image management.
Docker Command Reference