Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 123/ 160
07. CI/CD, Registries & Production Operations

Authenticating, Pushing & Pulling from Private Registries

Login, tag, push, and pull from private registries in local and CI contexts.

Beginnerdocker login · push3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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.4 for 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

Loading interactive 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.

Concrete docker login setup

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

Key takeaway: Prove push with 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.

Deliberate failure test

Exercise this failure safely: echoing a token on the command line or storing a registry password in a checked-in Docker config.

Key takeaway: Workload identity removes long-lived credentials but requires trust-policy setup; scoped PATs are a simpler fallback with rotation cost.

How it works, step by step

Step 1 of 4
Design

1. 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.

Keep push rights in the publisher and pull rights in the runtime/deployment role, and never use the same broad token for both.
Key numbers at this step
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/expiry in 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

Explicit docker login
Best for: Login, tag, push, and pull from private registries in local and CI contexts, with a reviewed runbook.

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.

Ambient default
Best for: Short-lived push experiments with low blast radius.

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.

Managed pull
Best for: Teams that centralize pull policy across many workloads.

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.4 as proof and skipping logout 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.4 address 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?
Interview tip: Give one concrete operation-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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Self-Hosting Private Container Registries (Docker Registry, Harbor)
Next topic
Image Retention Policies, Garbage Collection & Vulnerability Gates