Image Tagging and Versioning Strategies
What you'll learn: How to systematically tag and version container images so teams know exactly which code is running in each environment.
Why Tags Matter
When you build a container image, you create a snapshot of your application. Without a clear naming strategy, you'd quickly lose track of which image contains which code version. Tags are labels you attach to images (like myapp:v1.2.3) that help identify them.
Think of tags like revision numbers on documents—"Draft 1" vs "Final" vs "2024-Q1-Release" all tell you something meaningful about what you're looking at.
Common Tagging Patterns
Latest tag: Points to the most recent build. Convenient but dangerous—myapp:latest might mean different things in development vs production tomorrow.
Semantic versioning: Use major.minor.patch format (e.g., myapp:2.1.4). Breaking changes bump major, new features bump minor, bug fixes bump patch. This is ideal for production releases.
Git commit SHA: Tag images with their exact source code commit (e.g., myapp:a3f89b2). This creates perfect traceability between code and deployment.
Environment-specific tags: Some teams use myapp:dev, myapp:staging, myapp:prod, though this can create ambiguity about which actual version is deployed.
Managing Versions Across Environments
Use immutable tags for production—once v2.1.4 is built, never overwrite it. Development can use mutable tags like dev-latest that get updated frequently.
Promote the same image through environments: build once with commit SHA and semantic version, test in staging, then deploy that exact image to production. Never rebuild "the same thing" for production.
Key Takeaway: Use semantic versioning for releases, git SHAs for traceability, avoid relying on latest in production, and always promote the same immutable image through your deployment pipeline.