- Random Access Musings
- Posts
- Navigating Docker Images
Navigating Docker Images
Tagging, Renaming, and Using Docker Hub

Hello Muser!
In the last newsletter, we covered the relationships between software artifacts and registries. Building on that, this time around, we're focusing on Docker’s capabilities from tagging to sharing. We’ll look at the essentials of tagging Docker images and the nuances of Docker Hub.
As always, I'm all ears for your thoughts! What have your experiences with Docker been?


Image by storyset on freepik
Docker Images: A Brief Recap
Remember our hands-on session with crafting an nginx Docker image? This image is our immutable template. Anywhere we use this image, we're ensuring consistent behavior across varied environments, regardless of the hardware or particulars of configuration. These images allow us to separate the requirements of the actual running software and the environment it's running in.
Now, let's explore how we can better manage and share these images.

Understanding Tagging in Docker
Tags in Docker serve as our versioning markers. Picture them as descriptive labels for different versions of our image. Here's the basics:
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
For our nginx image:
docker tag my-nginx-image:latest my-nginx-image:v1
Here, we’ve labeled our image with the v1
tag.
Tagging During Build
Efficiency tip: tag during the build process:
docker build -t my-nginx-image:v2 .
This simultaneously builds and tags our image as v2
.


Image by storyset on freepik
Sharing on Docker Hub
Docker Hub is like GitHub but for Docker images. As we discussed last time, It's a cloud-based registry where you can easily publish and pull Docker images. But before you can push to Docker Hub, you'll need an account.
Why Create a Docker Hub Account?
1. Public and Private Repositories: With a free Docker Hub account, you get one private repository and unlimited public repositories. Private repositories allow you to keep your Docker images confidential, accessible only to you or specific collaborators.
2. Version Control for Images: Like GitHub, Docker Hub offers versioning for your Docker images using tags. This makes it easier to maintain different versions of your applications.
3. Collaboration: Share your images with the broader community or invite collaborators to work on private repositories.
How to Create a Docker Hub Account:
1. Head over to Docker Hub.
2. Click on 'Sign Up' in the top right corner.
3. Fill in your details, choose a unique Docker ID (this is important as it will be part of the URL for all your Docker repositories), and set a password.
4. Verify your email, and you're all set!
Once your account is set up and you’re logged in, pushing images is a breeze:
# Log into Docker Hub from the command line
docker login
# Tag your image
docker tag my-nginx-image:latest [your-docker-id]/my-nginx-image:latest
# Push your image
docker push [your-docker-id]/my-nginx-image:latest
Remember, replace [your-docker-id]
with the Docker ID you chose during sign up.


Renaming and Retagging: Docker Housekeeping
Renaming or retagging might be in order occasionally:
1. Renaming:
Use the docker tag
command:
docker tag [old-name]:[old-tag] [new-name]:[new-tag]
2. Retagging:
Similarly:
docker tag [image-name]:[old-tag] [image-name]:[new-tag]

Peeking Under the Hood with docker images
Once you've done some tagging, you might be curious to see all the Docker images you have on your local system, especially with their respective tags.
docker images
Here’s what you could see after our tagging exercise:
REPOSITORY TAG IMAGE ID CREATED SIZE
my-nginx-image v2 d4f7bfb3c872 2 hours ago 126MB
my-nginx-image v1 f1b10f842f44 2 hours ago 126MB
my-nginx-image latest a3ed99d648d6 2 hours ago 126MB
ubuntu latest d131e0fa2585 2 days ago 102MB
From this output, you can observe:
The
REPOSITORY
column lists the name of the Docker image.The
TAG
column shows the tag associated with that image. Notice ourv1
andv2
tags formy-nginx-image
.IMAGE ID
provides a unique identifier for each image version.CREATED
andSIZE
give you an idea about the age and footprint of each image respectively.
This view can be crucial for housekeeping, ensuring you're working with the correct versions, and helps to manage storage by occasionally purging old or unnecessary images.

The Docker Pipeline: A Recap
1. Craft a Dockerfile: Define your environment.
2. Build the Image: docker build -t [name]:[tag] .
3. Tag the Image: Label for versions or metadata.
4. Run the Image: Instantiate a container.
5. Push to Docker Hub: Spread the word.
Footnote: Pushing to other registries like Quay or Harbor? Just ensure you’re logged into the right registry. For instance, if pushing to an internal Harbor instance, you might tag and push using:
docker tag my-nginx-image:latest myregistry.example.com/myproject/my-nginx-image:latest
docker push myregistry.example.com/myproject/my-nginx-image:latest
Make sure you adjust the URL during tagging and pushing according to your registry's endpoint.

There are many more aspects of using Docker that I haven’t covered here. If you haven’t already subscribed, you’ll get a PDF cheat sheet with 200+ useful CLI commands for devops tools which includes a full page of Docker commands!
Have any questions or experiences to share about Docker image management? Leave a comment below. Also, your comments help me understand what you're curious about, and what topics you'd like to see covered next! I'd love to hear from you!

Enjoyed this post? Share with your colleagues who might find this useful!
Keep learning and keep growing,
Reply