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 40/ 160
02. Dockerfiles & Image Building

Dockerfile Linting & Best Practices with Hadolint

Lint Dockerfiles with Hadolint and adopt community best-practice rules.

IntermediateHadolint · Lint Rules3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Encode a small reviewed rule baseline in CI rather than rediscovering Dockerfile mistakes through slow or unsafe image builds.

Think of it like…

Hadolint is a copy editor for the recipe; it can flag unclear syntax and bad habits, but it cannot taste the finished meal or certify every ingredient.

Where you’ve seen it

In practice, hadolint --failure-threshold warning --trusted-registry docker.io --trusted-registry ghcr.io deploy/Dockerfile is the concrete move for this job: lint Dockerfiles with Hadolint and adopt community best-practice rules. The release is not accepted until run hadolint on every Dockerfile in CI and fail pull requests on a warning while checking the allowlist in .hadolint.yaml confirms the result.

Words you’ll hear

Hadolint
The implementation control in hadolint --failure-threshold warning --trusted-registry docker.io --trusted-registry ghcr.io deploy/Dockerfile for lint Dockerfiles with Hadolint and adopt community best-practice rules.
Lint Rules
The result to observe with run hadolint on every Dockerfile in CI and fail pull requests on a warning while checking the allowlist in .hadolint.yaml, rather than infer from a successful command alone.
Best Practices
The production boundary exposed when suppressing every DL rule globally, or treating a clean lint result as proof that image contents and supply-chain identity are safe.

Visual diagram

Loading interactive diagram

Theory & deep dive

Hadolint control path

The concrete mechanism is hadolint --failure-threshold warning --trusted-registry docker.io --trusted-registry ghcr.io deploy/Dockerfile. The observable result is run hadolint on every Dockerfile in CI and fail pull requests on a warning while checking the allowlist in .hadolint.yaml; if those disagree, inspect the runtime evidence before changing unrelated settings.

Lint Dockerfiles with Hadolint and adopt community best-practice rules. Keep Hadolint, Lint Rules and Best Practices in the same deployment record so the intent and the observed state cannot drift apart.

Concrete Hadolint setup

hadolint --failure-threshold warning --trusted-registry docker.io --trusted-registry ghcr.io deploy/Dockerfile

Key takeaway: Prove Lint Rules with run hadolint on every Dockerfile in CI and fail pull requests on a warning while checking the allowlist in .hadolint.yaml, not with command success alone.

Best Practices failure boundary

Lint is guidance, not a security scanner: it cannot prove package CVEs, runtime privileges or a malicious base. Ignoring rules should include an adjacent reason and, ideally, a code such as DL3008 for an intentional package pin policy. The narrow failure to design for is suppressing every DL rule globally, or treating a clean lint result as proof that image contents and supply-chain identity are safe.

Accept this compromise explicitly: Strict lint creates predictable images; threshold and ignore policies prevent legacy or context-specific rules from blocking all delivery. The controlled check-run hadolint on every Dockerfile in CI and fail pull requests on a warning while checking the allowlist in .hadolint.yaml-also identifies the point where a different design is safer.

Deliberate failure test

Exercise this failure safely: suppressing every DL rule globally, or treating a clean lint result as proof that image contents and supply-chain identity are safe.

Key takeaway: Strict lint creates predictable images; threshold and ignore policies prevent legacy or context-specific rules from blocking all delivery.

How it works, step by step

Step 1 of 4
Design

1. State the boundary

Write down why the workload needs this: Lint is guidance, not a security scanner: it cannot prove package CVEs, runtime privileges or a malicious base. Ignoring rules should include an adjacent reason and, ideally, a code such as DL3008 for an intentional package pin policy.

Encode a small reviewed rule baseline in CI rather than rediscovering Dockerfile mistakes through slow or unsafe image builds.
Key numbers at this step
Intent
Hadolint

When to use it & trade-offs

What it is

Hadolint parses a Dockerfile, reports Docker best-practice rules and can run a shell analyzer over RUN instructions. It catches missing version pins, apt cleanup problems, relative WORKDIR, invalid JSON exec form and other maintainability issues before an image reaches CI.

Why it matters: Lint is guidance, not a security scanner: it cannot prove package CVEs, runtime privileges or a malicious base. Ignoring rules should include an adjacent reason and, ideally, a code such as DL3008 for an intentional package pin policy.

When to reach for it

  • The fit is strongest for this job: lint Dockerfiles with Hadolint and adopt community best-practice rules. Pair it with run hadolint on every Dockerfile in CI and fail pull requests on a warning while checking the allowlist in .hadolint.yaml in the runbook.
  • Production Hadolint changes should make Lint Rules observable through hadolint --failure-threshold warning --trusted-registry docker.io --trusted-registry ghcr.io deploy/Dockerfile, rather than trusting the runtime default.
  • Keep a rollback example for the case where suppressing every DL rule globally, or treating a clean lint result as proof that image contents and supply-chain identity are safe.

When to avoid or be careful

  • Do not accept command success while the system can still fail by suppressing every DL rule globally, or treating a clean lint result as proof that image contents and supply-chain identity are safe.
  • Avoid erasing Best Practices protection merely to dodge this cost: “Strict lint creates predictable images; threshold and ignore policies prevent legacy or context-specific rules from blocking all delivery”.
  • Do not replace the evidence path-run hadolint on every Dockerfile in CI and fail pull requests on a warning while checking the allowlist in .hadolint.yaml-with a screenshot or a mutable tag.

hadolint --failure-threshold warning --trusted-registry docker.io --trusted-registry ghcr.io deploy/Dockerfile: practical choices

Explicit Hadolint
Best for: Lint Dockerfiles with Hadolint and adopt community best-practice rules, with a reviewed runbook.

Strengths: Hadolint parses a Dockerfile, reports Docker best-practice rules and can run a shell analyzer over RUN instructions. It catches missing version pins, apt cleanup problems, relative WORKDIR, invalid JSON exec form and other maintainability issues before an image reaches CI.

Watch out: Strict lint creates predictable images; threshold and ignore policies prevent legacy or context-specific rules from blocking all delivery.

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

Strengths: It can begin with hadolint --failure-threshold warning --trusted-registry docker.io --trusted-registry ghcr.io deploy/Dockerfile and fewer surrounding controls.

Watch out: It silently accepts suppressing every DL rule globally, or treating a clean lint result as proof that image contents and supply-chain identity are safe, which makes the result hard to reproduce after promotion.

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

Strengths: Lint is guidance, not a security scanner: it cannot prove package CVEs, runtime privileges or a malicious base. Ignoring rules should include an adjacent reason and, ideally, a code such as DL3008 for an intentional package pin policy.

Watch out: The platform adds an ownership and debugging layer; retain run hadolint on every Dockerfile in CI and fail pull requests on a warning while checking the allowlist in .hadolint.yaml as the direct check.

Interview signals & numbers to know

When this topic comes up

  • hadolint --failure-threshold warning --trusted-registry docker.io --trusted-registry ghcr.io deploy/Dockerfile
  • run hadolint on every Dockerfile in CI and fail pull requests on a warning while checking the allowlist in .hadolint.yaml
  • Failure signature: suppressing every DL rule globally, or treating a clean lint result as proof that image contents and supply-chain identity are safe
  • Trade-off: Strict lint creates predictable images; threshold and ignore policies prevent legacy or context-specific rules from blocking all delivery.

Benchmarks & rules of thumb

1 .hadolint.yaml -
can hold trusted registries and ignored rules
warning -
example CI failure threshold
DL/DL3xxx -
rule identifiers used for reviewable exceptions

Common mistakes & follow-ups

Common interview mistakes

  • Treating a successful hadolint --failure-threshold warning --trusted-registry docker.io --trusted-registry ghcr.io deploy/Dockerfile as proof and skipping run hadolint on every Dockerfile in CI and fail pull requests on a warning while checking the allowlist in .hadolint.yaml.
  • Suppressing every DL rule globally, or treating a clean lint result as proof that image contents and supply-chain identity are safe
  • Optimizing Hadolint without accepting that strict lint creates predictable images; threshold and ignore policies prevent legacy or context-specific rules from blocking all delivery.

Likely interviewer follow-ups

  • Why does hadolint --failure-threshold warning --trusted-registry docker.io --trusted-registry ghcr.io deploy/Dockerfile address Hadolint here rather than through application code?
  • How would you distinguish healthy Lint Rules from the failure “suppressing every DL rule globally, or treating a clean lint result as proof that image contents and supply-chain identity are safe” using run hadolint on every Dockerfile in CI and fail pull requests on a warning while checking the allowlist in .hadolint.yaml?
  • When would this trade-off-“Strict lint creates predictable images; threshold and ignore policies prevent legacy or context-specific rules from blocking all delivery”-justify a different Best Practices design?
Interview tip: Give one concrete operation-hadolint --failure-threshold warning --trusted-registry docker.io --trusted-registry ghcr.io deploy/Dockerfile-and one proof-run hadolint on every Dockerfile in CI and fail pull requests on a warning while checking the allowlist in .hadolint.yaml. Then name the boundary: suppressing every DL rule globally, or treating a clean lint result as proof that image contents and supply-chain identity are safe.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Dockerfile Linting & Best Practices with Hadolint with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Inspecting Image History & Layer Sizes (docker history, dive)
Next topic
Ephemeral Container Filesystems & Why Data Gets Lost