Authenticating, Pushing & Pulling from Private Registries
Login, tag, push, and pull from private registries in local and CI contexts.
In plain words
Keep push rights in the publisher and pull rights in the runtime/deployment role, and never use the same broad token for both.
Think of it like…
Registry auth is a shipping badge with separate loading-dock and reader permissions, not one master card reused by every courier.
Where you’ve seen it
In practice, docker login ghcr.io -u $GITHUB_ACTOR --password-stdin && docker tag api:ci ghcr.io/acme/api:2.1.4 && docker push ghcr.io/acme/api:2.1.4 is the concrete move for this job: login, tag, push, and pull from private registries in local and CI contexts. The release is not accepted until logout in a finally step, docker buildx imagetools inspect the release digest, and audit CI token scopes/expiry confirms the result.
Words you’ll hear
- docker login
- The implementation control in
docker login ghcr.io -u $GITHUB_ACTOR --password-stdin && docker tag api:ci ghcr.io/acme/api:2.1.4 && docker push ghcr.io/acme/api:2.1.4for login, tag, push, and pull from private registries in local and CI contexts. - push
- The result to observe with
logout in a finally step, docker buildx imagetools inspect the release digest, and audit CI token scopes/expiry, rather than infer from a successful command alone. - pull
- The production boundary exposed when echoing a token on the command line or storing a registry password in a checked-in Docker config.
Visual diagram
Theory & deep dive
docker login control path
The concrete mechanism is docker login ghcr.io -u $GITHUB_ACTOR --password-stdin && docker tag api:ci ghcr.io/acme/api:2.1.4 && docker push ghcr.io/acme/api:2.1.4. The observable result is logout in a finally step, docker buildx imagetools inspect the release digest, and audit CI token scopes/expiry; if those disagree, inspect the runtime evidence before changing unrelated settings.
Login, tag, push, and pull from private registries in local and CI contexts. Keep docker login, push and pull in the same deployment record so the intent and the observed state cannot drift apart.
docker login ghcr.io -u $GITHUB_ACTOR --password-stdin && docker tag api:ci ghcr.io/acme/api:2.1.4 && docker push ghcr.io/acme/api:2.1.4
logout in a finally step, docker buildx imagetools inspect the release digest, and audit CI token scopes/expiry, not with command success alone.pull failure boundary
A PAT embedded in .docker/config.json can survive on a runner, and registry/repo without the correct namespace results in denied or wrong-destination pushes. Pulling by tag then does not prove the tested digest if the tag moves. The narrow failure to design for is echoing a token on the command line or storing a registry password in a checked-in Docker config.
Accept this compromise explicitly: Workload identity removes long-lived credentials but requires trust-policy setup; scoped PATs are a simpler fallback with rotation cost. The controlled check-logout in a finally step, docker buildx imagetools inspect the release digest, and audit CI token scopes/expiry-also identifies the point where a different design is safer.
Exercise this failure safely: echoing a token on the command line or storing a registry password in a checked-in Docker config.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: A PAT embedded in .docker/config.json can survive on a runner, and registry/repo without the correct namespace results in denied or wrong-destination pushes. Pulling by tag then does not prove the tested digest if the tag moves.
- Intent
- docker login
When to use it & trade-offs
What it is
docker login records a credential helper/config entry used for registry API tokens; buildx/CI should obtain short-lived cloud or OIDC-derived tokens, tag the local image with the full registry namespace, push, and later pull by digest.
Why it matters: A PAT embedded in .docker/config.json can survive on a runner, and registry/repo without the correct namespace results in denied or wrong-destination pushes. Pulling by tag then does not prove the tested digest if the tag moves.
When to reach for it
- The fit is strongest for this job: login, tag, push, and pull from private registries in local and CI contexts. Pair it with
logout in a finally step, docker buildx imagetools inspect the release digest, and audit CI token scopes/expiryin the runbook. - Production docker login changes should make push observable through
docker login ghcr.io -u $GITHUB_ACTOR --password-stdin && docker tag api:ci ghcr.io/acme/api:2.1.4 && docker push ghcr.io/acme/api:2.1.4, rather than trusting the runtime default. - Keep a rollback example for the case where echoing a token on the command line or storing a registry password in a checked-in Docker config.
When to avoid or be careful
- Do not accept command success while the system can still fail by echoing a token on the command line or storing a registry password in a checked-in Docker config.
- Avoid erasing pull protection merely to dodge this cost: “Workload identity removes long-lived credentials but requires trust-policy setup; scoped PATs are a simpler fallback with rotation cost”.
- Do not replace the evidence path-
logout in a finally step, docker buildx imagetools inspect the release digest, and audit CI token scopes/expiry-with a screenshot or a mutable tag.
docker login ghcr.io -u $GITHUB_ACTOR --password-stdin && docker tag api:ci ghcr.io/acme/api:2.1.4 && docker push ghcr.io/acme/api:2.1.4: practical choices
Strengths: docker login records a credential helper/config entry used for registry API tokens; buildx/CI should obtain short-lived cloud or OIDC-derived tokens, tag the local image with the full registry namespace, push, and later pull by digest.
Watch out: Workload identity removes long-lived credentials but requires trust-policy setup; scoped PATs are a simpler fallback with rotation cost.
Strengths: It can begin with docker login ghcr.io -u $GITHUB_ACTOR --password-stdin && docker tag api:ci ghcr.io/acme/api:2.1.4 && docker push ghcr.io/acme/api:2.1.4 and fewer surrounding controls.
Watch out: It silently accepts echoing a token on the command line or storing a registry password in a checked-in Docker config, which makes the result hard to reproduce after promotion.
Strengths: A PAT embedded in .docker/config.json can survive on a runner, and registry/repo without the correct namespace results in denied or wrong-destination pushes. Pulling by tag then does not prove the tested digest if the tag moves.
Watch out: The platform adds an ownership and debugging layer; retain logout in a finally step, docker buildx imagetools inspect the release digest, and audit CI token scopes/expiry as the direct check.
Interview signals & numbers to know
When this topic comes up
- docker login ghcr.io -u $GITHUB_ACTOR --password-stdin && docker tag api:ci ghcr.io/acme/api:2.1.4 && docker push ghcr.io/acme/api:2.1.4
- logout in a finally step, docker buildx imagetools inspect the release digest, and audit CI token scopes/expiry
- Failure signature: echoing a token on the command line or storing a registry password in a checked-in Docker config
- Trade-off: Workload identity removes long-lived credentials but requires trust-policy setup; scoped PATs are a simpler fallback with rotation cost.
Benchmarks & rules of thumb
- 1 token scope/purpose
- push or pull per role
- 0 characters in logs
- credential values must be redacted
- 2 references
- mutable tag plus immutable manifest digest
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
docker login ghcr.io -u $GITHUB_ACTOR --password-stdin && docker tag api:ci ghcr.io/acme/api:2.1.4 && docker push ghcr.io/acme/api:2.1.4as proof and skippinglogout in a finally step, docker buildx imagetools inspect the release digest, and audit CI token scopes/expiry. - Echoing a token on the command line or storing a registry password in a checked-in Docker config
- Optimizing docker login without accepting that workload identity removes long-lived credentials but requires trust-policy setup; scoped PATs are a simpler fallback with rotation cost.
Likely interviewer follow-ups
- Why does
docker login ghcr.io -u $GITHUB_ACTOR --password-stdin && docker tag api:ci ghcr.io/acme/api:2.1.4 && docker push ghcr.io/acme/api:2.1.4address docker login here rather than through application code? - How would you distinguish healthy push from the failure “echoing a token on the command line or storing a registry password in a checked-in Docker config” using
logout in a finally step, docker buildx imagetools inspect the release digest, and audit CI token scopes/expiry? - When would this trade-off-“Workload identity removes long-lived credentials but requires trust-policy setup; scoped PATs are a simpler fallback with rotation cost”-justify a different pull design?
docker login ghcr.io -u $GITHUB_ACTOR --password-stdin && docker tag api:ci ghcr.io/acme/api:2.1.4 && docker push ghcr.io/acme/api:2.1.4-and one proof-logout in a finally step, docker buildx imagetools inspect the release digest, and audit CI token scopes/expiry. Then name the boundary: echoing a token on the command line or storing a registry password in a checked-in Docker config.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Authenticating, Pushing & Pulling from Private Registries with generative AI interview Q&A and hands-on practice.