DevOps Day 38: Docker Image Management and Tagging¶
Today's task was a great exercise in a fundamental Docker skill: image management. My objective was to pull a specific image from a public registry and then give it a new, local "alias" or tag. This is a very common workflow for organizing images and preparing them for different environments.
I learned the crucial concept that docker tag does not create a new, heavy copy of an image, but simply a lightweight pointer to the existing one. This document is my first-person guide to that simple but essential process.
The Task¶
My objective was to manage an image on App Server 3. The specific requirements were:
- Pull the busybox:musl image.
- Create a new tag for this image, named busybox:local.
My Step-by-Step Solution¶
-
Connect to the Server: I first logged into App Server 3 (
ssh banner@stapp03). -
Pull the Image: I used the
docker pullcommand to download the specified image from Docker Hub.sudo docker pull busybox:musl -
Re-tag the Image: This was the core of the task. I used the
docker tagcommand to create the new alias.sudo docker tag busybox:musl busybox:local -
Verification: The crucial final step was to confirm that the new tag was created and that it pointed to the same underlying image. I used the
docker imagescommand.The output clearly showed two entries forsudo docker imagesbusybox, and most importantly, they both had the exact same Image ID. This was the definitive proof that my task was successful.REPOSITORY TAG IMAGE ID CREATED SIZE busybox local a9286defaba4 ... 1.4MB busybox musl a9286defaba4 ... 1.4MB
Key Concepts (The "What & Why")¶
-
Docker Image: An image is a read-only template with instructions for creating a Docker container. It contains the application, its runtime, and all its dependencies.
-
Image Tag: A tag is a label or a pointer to a specific version of an image. In busybox:musl, busybox is the repository name and musl is the tag. If you don't specify a tag, Docker defaults to using latest.
-
docker pull: This command is used to download an image from a registry (like Docker Hub).
-
docker tag (The Alias): This is the most important concept from this task. The docker tag command creates a new tag that refers to an existing image. It does not duplicate the image data. This is a very fast and space-efficient operation. I learned to think of it as creating a shortcut or an alias.
-
Why Re-tag? Tagging is a key part of the Docker workflow.
-
For Clarity: Giving an image a project-specific name (like busybox:local) makes its purpose clearer.
-
For Versioning: You can tag the same image as my-app:v1.2, my-app:stable, and my-app:latest.
-
For Pushing to a Registry: Before you can push an image to a registry, you must tag it with the registry's address (e.g.,
docker tag my-app:latest myregistry.com/my-app:latest).
-
Commands I Used¶
-
sudo docker pull busybox:musl: The command to download the specified image from Docker Hub. -
sudo docker tag busybox:musl busybox:local: The main command for this task. It creates a new tag busybox:local that points to the same image ID asbusybox:musl. The syntax is docker tag<SOURCE_IMAGE:TAG> <TARGET_IMAGE:TAG>. -
sudo docker images: My verification command. It lists all the Docker images on the local system. I used it to confirm that both tags were present and shared the same Image ID.