Earlier, we pulled some images from the Docker Hub and learned how pull works. Take the following example of an NGINX image.
[email protected]:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 8a0f0f376e66 40 hours ago 179MB
If we break it down, we can see the following values of the image.
- Repository; where the image is stored publically, here it is “nginx”.
- Tag; the tag can be a version or any other name, it’s “latest” here.
- Image ID; the unique ID of the image
- Created; time when the image was created.
- Size; the size of the image.
Following is the general syntax of the docker tag
command:
docker tag source_image:tag target_image:tag
The source image locally on the system is nginx:latest
. We want to change the tag to 1.1 instead of “latest”. Let’s assume it would be the first version of the webserver.
Here is the docker tag
command for that:
docker tag nginx:latest nginx:1.1
- Source image: nginx:latest
- Target image: nginx:1.1
Now see the following image showing the images on our system. The docker command does not rename the tag only. It creates a new image with a new tag. You can see the image ID is the same for both images.