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 125/ 160
07. CI/CD, Registries & Production Operations

Automated Docker Builds in GitHub Actions

Build and push images from GitHub Actions workflows on every PR and release.

BeginnerGitHub Actions · Build3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Treat every image as build provenance: source SHA, workflow identity, platform, tag/digest, SBOM and scan result should connect.

Think of it like…

The workflow is an assembly line with the Git commit as the work order and the emitted digest as the sealed serial number.

Where you’ve seen it

In practice, uses: docker/build-push-action@v6; with: context=., push=${{ github.event_name != "pull_request" }}, tags=ghcr.io/acme/api:${{ github.sha }} is the concrete move for this job: build and push images from GitHub Actions workflows on every PR and release. The release is not accepted until inspect the step summary digest and run a no-push PR from a fork, then verify the release branch has OIDC read/package write only confirms the result.

Words you’ll hear

GitHub Actions
The implementation control in uses: docker/build-push-action@v6; with: context=., push=${{ github.event_name != "pull_request" }}, tags=ghcr.io/acme/api:${{ github.sha }} for build and push images from GitHub Actions workflows on every PR and release.
Build
The result to observe with inspect the step summary digest and run a no-push PR from a fork, then verify the release branch has OIDC read/package write only, rather than infer from a successful command alone.
Push
The production boundary exposed when exposing registry write secrets to fork PRs, or tagging by branch only and losing the source SHA in image metadata.

Visual diagram

Loading interactive diagram

Theory & deep dive

GitHub Actions control path

The concrete mechanism is uses: docker/build-push-action@v6; with: context=., push=${{ github.event_name != "pull_request" }}, tags=ghcr.io/acme/api:${{ github.sha }}. The observable result is inspect the step summary digest and run a no-push PR from a fork, then verify the release branch has OIDC read/package write only; if those disagree, inspect the runtime evidence before changing unrelated settings.

Build and push images from GitHub Actions workflows on every PR and release. Keep GitHub Actions, Build and Push in the same deployment record so the intent and the observed state cannot drift apart.

Concrete GitHub Actions setup

uses: docker/build-push-action@v6; with: context=., push=${{ github.event_name != "pull_request" }}, tags=ghcr.io/acme/api:${{ github.sha }}

Key takeaway: Prove Build with inspect the step summary digest and run a no-push PR from a fork, then verify the release branch has OIDC read/package write only, not with command success alone.

Push failure boundary

A public fork pull_request can contain hostile Dockerfile code, so privileged credentials and --privileged runners are never passed to untrusted PRs. Mutable actions/tags and missing permissions: contents: read make the supply chain harder to audit. The narrow failure to design for is exposing registry write secrets to fork PRs, or tagging by branch only and losing the source SHA in image metadata.

Accept this compromise explicitly: build-push-action simplifies standard metadata/cache; a custom script gives flexibility but must reproduce provenance and least-privilege semantics. The controlled check-inspect the step summary digest and run a no-push PR from a fork, then verify the release branch has OIDC read/package write only-also identifies the point where a different design is safer.

Deliberate failure test

Exercise this failure safely: exposing registry write secrets to fork PRs, or tagging by branch only and losing the source SHA in image metadata.

Key takeaway: build-push-action simplifies standard metadata/cache; a custom script gives flexibility but must reproduce provenance and least-privilege semantics.

How it works, step by step

Step 1 of 4
Design

1. State the boundary

Write down why the workload needs this: A public fork pull_request can contain hostile Dockerfile code, so privileged credentials and --privileged runners are never passed to untrusted PRs. Mutable actions/tags and missing permissions: contents: read make the supply chain harder to audit.

Treat every image as build provenance: source SHA, workflow identity, platform, tag/digest, SBOM and scan result should connect.
Key numbers at this step
Intent
GitHub Actions

When to use it & trade-offs

What it is

A Docker workflow uses a runner, checkout, QEMU/buildx setup, short-lived registry authentication and build-push-action to emit a reviewed tag plus digest. Pull requests build without push or use permissions-bound preview repositories; releases push from a protected workflow.

Why it matters: A public fork pull_request can contain hostile Dockerfile code, so privileged credentials and --privileged runners are never passed to untrusted PRs. Mutable actions/tags and missing permissions: contents: read make the supply chain harder to audit.

When to reach for it

  • The fit is strongest for this job: build and push images from GitHub Actions workflows on every PR and release. Pair it with inspect the step summary digest and run a no-push PR from a fork, then verify the release branch has OIDC read/package write only in the runbook.
  • Production GitHub Actions changes should make Build observable through uses: docker/build-push-action@v6; with: context=., push=${{ github.event_name != "pull_request" }}, tags=ghcr.io/acme/api:${{ github.sha }}, rather than trusting the runtime default.
  • Keep a rollback example for the case where exposing registry write secrets to fork PRs, or tagging by branch only and losing the source SHA in image metadata.

When to avoid or be careful

  • Do not accept command success while the system can still fail by exposing registry write secrets to fork PRs, or tagging by branch only and losing the source SHA in image metadata.
  • Avoid erasing Push protection merely to dodge this cost: “build-push-action simplifies standard metadata/cache; a custom script gives flexibility but must reproduce provenance and least-privilege semantics”.
  • Do not replace the evidence path-inspect the step summary digest and run a no-push PR from a fork, then verify the release branch has OIDC read/package write only-with a screenshot or a mutable tag.

uses: docker/build-push-action@v6; with: context=., push=${{ github.event_name != "pull_request" }}, tags=ghcr.io/acme/api:${{ github.sha }}: practical choices

Explicit GitHub Actions
Best for: Build and push images from GitHub Actions workflows on every PR and release, with a reviewed runbook.

Strengths: A Docker workflow uses a runner, checkout, QEMU/buildx setup, short-lived registry authentication and build-push-action to emit a reviewed tag plus digest. Pull requests build without push or use permissions-bound preview repositories; releases push from a protected workflow.

Watch out: build-push-action simplifies standard metadata/cache; a custom script gives flexibility but must reproduce provenance and least-privilege semantics.

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

Strengths: It can begin with uses: docker/build-push-action@v6; with: context=., push=${{ github.event_name != "pull_request" }}, tags=ghcr.io/acme/api:${{ github.sha }} and fewer surrounding controls.

Watch out: It silently accepts exposing registry write secrets to fork PRs, or tagging by branch only and losing the source SHA in image metadata, which makes the result hard to reproduce after promotion.

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

Strengths: A public fork pull_request can contain hostile Dockerfile code, so privileged credentials and --privileged runners are never passed to untrusted PRs. Mutable actions/tags and missing permissions: contents: read make the supply chain harder to audit.

Watch out: The platform adds an ownership and debugging layer; retain inspect the step summary digest and run a no-push PR from a fork, then verify the release branch has OIDC read/package write only as the direct check.

Interview signals & numbers to know

When this topic comes up

  • uses: docker/build-push-action@v6; with: context=., push=${{ github.event_name != "pull_request" }}, tags=ghcr.io/acme/api:${{ github.sha }}
  • inspect the step summary digest and run a no-push PR from a fork, then verify the release branch has OIDC read/package write only
  • Failure signature: exposing registry write secrets to fork PRs, or tagging by branch only and losing the source SHA in image metadata
  • Trade-off: build-push-action simplifies standard metadata/cache; a custom script gives flexibility but must reproduce provenance and least-privilege semantics.

Benchmarks & rules of thumb

1 digest output -
primary release artifact ID
2 trust contexts -
untrusted PR and protected release differ
contents: read -
example minimal source permission

Common mistakes & follow-ups

Common interview mistakes

  • Treating a successful uses: docker/build-push-action@v6; with: context=., push=${{ github.event_name != "pull_request" }}, tags=ghcr.io/acme/api:${{ github.sha }} as proof and skipping inspect the step summary digest and run a no-push PR from a fork, then verify the release branch has OIDC read/package write only.
  • Exposing registry write secrets to fork PRs, or tagging by branch only and losing the source SHA in image metadata
  • Optimizing GitHub Actions without accepting that build-push-action simplifies standard metadata/cache; a custom script gives flexibility but must reproduce provenance and least-privilege semantics.

Likely interviewer follow-ups

  • Why does uses: docker/build-push-action@v6; with: context=., push=${{ github.event_name != "pull_request" }}, tags=ghcr.io/acme/api:${{ github.sha }} address GitHub Actions here rather than through application code?
  • How would you distinguish healthy Build from the failure “exposing registry write secrets to fork PRs, or tagging by branch only and losing the source SHA in image metadata” using inspect the step summary digest and run a no-push PR from a fork, then verify the release branch has OIDC read/package write only?
  • When would this trade-off-“build-push-action simplifies standard metadata/cache; a custom script gives flexibility but must reproduce provenance and least-privilege semantics”-justify a different Push design?
Interview tip: Give one concrete operation-uses: docker/build-push-action@v6; with: context=., push=${{ github.event_name != "pull_request" }}, tags=ghcr.io/acme/api:${{ github.sha }}-and one proof-inspect the step summary digest and run a no-push PR from a fork, then verify the release branch has OIDC read/package write only. Then name the boundary: exposing registry write secrets to fork PRs, or tagging by branch only and losing the source SHA in image metadata.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Automated Docker Builds in GitHub Actions with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Image Retention Policies, Garbage Collection & Vulnerability Gates
Next topic
Speeding Up CI Builds with Registry & GitHub Actions Layer Caching