Docker Tag Command
# Docker tag Command
[Docker Command Manual](#)
* * *
The `docker tag` command is used to create an alias (tag) for a local image. By tagging an image, you can identify and manage images using easier-to-remember names or version numbers.
### Syntax
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
* **`SOURCE_IMAGE[:TAG]`**: The source image name and tag. The tag defaults to `latest`.
* **`TARGET_IMAGE[:TAG]`**: The target image name and tag. The tag defaults to `latest`.
**1. Tagging an Image**
docker tag myimage:1.0 myrepo/myimage:latest
This will tag the local `myimage:1.0` image as `myrepo/myimage:latest`.
**2. Tagging an Image with Multiple Tags**
docker tag myimage:1.0 myrepo/myimage:stable docker tag myimage:1.0 myrepo/myimage:v1.0
This will tag `myimage:1.0` as both `myrepo/myimage:stable` and `myrepo/myimage:v1.0`.
**3. Tagging an Image for Pushing 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.
* * *
## Examples
### Tagging an 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
* Tags are just aliases for images; they do not create new image layers, so they do not occupy additional storage space.
* Tags should be concise and descriptive to facilitate identification and management of image versions.
* When using tags, ensure the naming complies with the registry's naming conventions.
The `docker tag` command is an essential tool for managing Docker images. By tagging images, you can conveniently identify, manage, and publish different versions of images. This command is applicable to various scenarios, including version management, image publishing, and image replication. When using it, ensure that tag names are standardized and descriptive to improve the efficiency and maintainability of image management.
* * Docker Command Manual](#)
YouTip