Lesson 7 of 30
The general CI/CD lesson in this platform's Practices track covers build-test-deploy as a pipeline shape. This one is narrower: the specific decisions a pipeline has to make once what it's shipping is a Docker image.
12 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 3
In a build-once-promote-everywhere pipeline, what does `docker tag registry.example.com/myapp:a1b2c3d registry.example.com/myapp:production` actually do?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
Once a pipeline's deployable artifact is a Docker image, one principle should govern almost every other decision: build once, promote the same image everywhere. CI builds and tags exactly one image per change, pushes it to a registry once, and every environment after that — staging, then production — pulls and runs that exact same image, never a fresh rebuild per environment.
The alternative (rebuilding the image separately for staging and for production) reintroduces the very problem containers exist to solve: two builds, even from identical source, aren't guaranteed identical — a base image update between builds, a registry serving a different "latest" of a dependency, or simple build-environment drift can produce a production image that was never actually the one tested in staging.
# In CI, after tests pass:
docker build -t registry.example.com/myapp:$(git rev-parse --short HEAD) .
docker push registry.example.com/myapp:$(git rev-parse --short HEAD)
# Promoting the SAME image to staging, then production — never rebuilding:
docker tag registry.example.com/myapp:a1b2c3d registry.example.com/myapp:staging
docker push registry.example.com/myapp:staging
# ...tests pass in staging...
docker tag registry.example.com/myapp:a1b2c3d registry.example.com/myapp:production
docker push registry.example.com/myapp:production
CI builds once and tags the image with the git SHA — a1b2c3d.
staging and production here are just additional tags pointing at the same image digest as the original git-SHA-tagged build — docker tag doesn't rebuild anything, it just adds another name for an image that already exists. The image that ran in staging is provably, byte-for-byte, the same one that reaches production.
aws ecr get-login-password) specifically so pipeline credentials can be rotated, scoped to push-only, and revoked independently of any individual's personal access."How do you make sure what's running in production is actually what was tested in staging?" is a real, senior-leaning question, and "build once, tag with something traceable like a git SHA, promote that same image forward" is a precise, confident answer — versus "we redeploy for each environment," which is the answer that reveals the gap this lesson exists to close.