Kritim Yantra
Apr 24, 2025
Tagging is one of Docker's most important features for organizing and versioning container images. Whether you're using official images from Docker Hub or creating your own custom images, understanding tags is essential for efficient container management.
In this guide, we'll cover:
nginx
, ubuntu
)A Docker tag is a label assigned to an image that helps identify different versions of the same image. Tags follow this format:
IMAGE_NAME:TAG
IMAGE_NAME
→ The repository name (e.g., nginx
, my-app
)TAG
→ A version identifier (e.g., latest
, 1.0
, v2.3.1
)If no tag is specified, Docker defaults to latest
.
Official images (e.g., nginx
, ubuntu
, python
) follow a structured tagging system to indicate different versions and variants.
latest
→ The most recent stable release.docker pull nginx:latest
docker pull ubuntu:20.04
docker pull python:3.9
Official images often provide lightweight variants:
-alpine
→ Smaller images based on Alpine Linux.docker pull nginx:alpine
-slim
→ Stripped-down versions (fewer pre-installed packages).docker pull python:3.9-slim
Some tags support multiple CPU architectures (e.g., amd64
, arm64
):
docker pull --platform linux/arm64 ubuntu:20.04
When building your own images, you should assign meaningful tags for version control.
Tag your image during the build process:
docker build -t my-app:1.0 .
my-app
→ Repository name.1.0
→ Version tag.You can assign multiple tags to the same image:
docker tag my-app:1.0 my-app:latest
docker tag my-app:1.0 my-app:stable
Use MAJOR.MINOR.PATCH
for better tracking:
docker build -t my-app:2.1.0 .
2
→ Major version (breaking changes)1
→ Minor version (new features)0
→ Patch version (bug fixes)For CI/CD pipelines, you can tag images with Git commit IDs:
docker build -t my-app:$(git rev-parse --short HEAD) .
Example output:
my-app:abc1234
Avoid latest
in Production
latest
can change unexpectedly—use fixed versions (my-app:1.2.3
).Use Descriptive Tags
backend-api:v2.3.1-prod
Clean Up Old Tags
docker rmi my-app:old-version
Sign & Verify Images (Advanced)
DOCKER_CONTENT_TRUST=1
) to prevent untrusted images.Tag Before Pushing to a Registry
docker tag my-app:1.0 my-company/my-app:1.0
docker push my-company/my-app:1.0
Scenario | Example Command |
---|---|
Pull official image | docker pull nginx:1.23-alpine |
Build & tag custom image | docker build -t my-app:1.0 . |
Add an additional tag | docker tag my-app:1.0 my-app:latest |
Push to a registry | docker push my-company/my-app:1.0 |
By following these tagging practices, you'll maintain better control over your Docker images, making deployments more reliable and traceable.
Happy Tagging! ️🐳
No comments yet. Be the first to comment!
Please log in to post a comment:
Sign in with Google