How do you version and tag Docker images for a .NET application as part of a CI/CD pipeline?
Short answer
A common convention tags images with both a unique, traceable identifier (like the Git commit SHA, ensuring every build is uniquely identifiable and immutable) and a semantic or environment-meaningful tag (like 'latest' for the most recent build, or a version number for…
Advertisement
AModel answer
A common convention tags images with both a unique, traceable identifier (like the Git commit SHA, ensuring every build is uniquely identifiable and immutable) and a semantic or environment-meaningful tag (like 'latest' for the most recent build, or a version number for releases), pushing both tags to the container registry so deployments can reference either the exact commit or a more human-friendly version.
docker build -t myregistry.io/myapp:${{ github.sha }} -t myregistry.io/myapp:v1.4.0 .
docker push myregistry.io/myapp:${{ github.sha }}
docker push myregistry.io/myapp:v1.4.0Real-world example
A team always deploys using the specific Git SHA tag (never 'latest') in their Kubernetes manifests, guaranteeing that a rollback or audit can always trace exactly which commit is running in production at any point in time.
Likely follow-ups
- Why is deploying with the 'latest' tag considered a bad practice for production?
- How do you clean up old, unused image tags from a registry over time?
Related topics