Practical Naming Techniques
Strategic Image Naming Approaches
1. Semantic Versioning Strategy
graph LR
A[Major Version] --> B[Minor Version] --> C[Patch Version]
Implementation Example
## Semantic versioning tags
docker build -t labex/webapp:1.2.3 .
docker build -t labex/webapp:1.2.4 .
2. Environment-Based Naming
Environment |
Naming Convention |
Example |
Development |
image:dev |
webapp:dev |
Staging |
image:staging |
webapp:staging |
Production |
image:prod |
webapp:prod |
## Include build number and git commit
docker build -t labex/backend:v1.0.0-build-123 \
--build-arg GIT_COMMIT=$(git rev-parse HEAD) .
4. Multi-Architecture Support
## Tag images for different architectures
docker build -t labex/app:arm64 --platform linux/arm64 .
docker build -t labex/app:amd64 --platform linux/amd64 .
Advanced Naming Techniques
Automated Naming Scripts
#!/bin/bash
VERSION=$(git describe --tags)
IMAGE_NAME="labex/myapp:${VERSION}"
docker build -t ${IMAGE_NAME} .
Naming Best Practices
- Use consistent naming patterns
- Include meaningful metadata
- Avoid generic tags like "latest"
- Document naming conventions
Practical Ubuntu 22.04 Workflow
## Create a comprehensive naming strategy
docker build \
-t labex/microservice:v1.2.3-ubuntu22.04 \
--label version=1.2.3 \
--label maintainer=devops \
.
## Verify image details
docker inspect labex/microservice:v1.2.3-ubuntu22.04
Image Naming Validation
## Check image naming compliance
docker images | grep labex/ | awk '{print $1":"$2}'
By implementing these practical naming techniques, developers can create more organized, traceable, and manageable Docker image ecosystems.