Question 147 of 997
Supply Chain SecurityhardMultiple SelectObjective-mapped

Dockerfile Security Best Practices for CKS

This CKS practice question tests your understanding of supply chain security. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

Which THREE of the following are best practices for Dockerfile security? (Select THREE)

Clue words in this question

Noticing these words before you look at the options changes how you read each choice.

  • Clue: "best"

    Why it matters: Signals that multiple options may be partially correct. Choose the option that most directly solves the exact problem described, not the one that sounds most complete.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Pin base image versions using SHA256 digests

Option B is correct because pinning base image versions using SHA256 digests ensures immutability and prevents the image from being silently updated to a potentially vulnerable version. Docker image tags (e.g., `ubuntu:latest`) are mutable and can point to different images over time, but a digest (e.g., `ubuntu@sha256:abc123...`) uniquely identifies a specific image manifest, guaranteeing that every build uses the exact same base image. This practice is a key supply chain security control to avoid dependency confusion or accidental inclusion of compromised base images.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Install debugging tools like curl and vim in the final image

    Why it's wrong here

    Installing debugging tools like curl and vim increases the attack surface and is not a security best practice. It is considered a bad practice for production images.

  • Pin base image versions using SHA256 digests

    Why this is correct

    Pinning base image versions using SHA256 digests ensures that the exact same image is used across builds, preventing unintended changes or vulnerabilities from updated tags.

    Clue confirmation

    The clue word "best" in the question point toward this answer.

    Related concept

    Read the scenario before looking for a memorised answer.

  • Specify a non-root user with the USER directive

    Why this is correct

    Specifying a non-root user with the USER directive reduces the risk of privilege escalation if the container is compromised.

    Clue confirmation

    The clue word "best" in the question point toward this answer.

    Related concept

    Read the scenario before looking for a memorised answer.

  • Use COPY instead of ADD for copying files

    Why it's wrong here

    Using COPY instead of ADD is a general best practice for build reliability, but it is not specifically a security control. The question's expected correct answers focus on security-related practices.

  • Use multi-stage builds to reduce image size

    Why this is correct

    Multi-stage builds help reduce the final image size by separating build dependencies from runtime, thereby minimizing the attack surface.

    Clue confirmation

    The clue word "best" in the question point toward this answer.

    Related concept

    Read the scenario before looking for a memorised answer.

Common exam traps

Common exam trap: answer the scenario, not the keyword

The CKS exam often tests the distinction between 'best practices for security' and 'general best practices' — candidates may incorrectly select D (COPY vs ADD) because it is a common recommendation, but the CKS exam specifically focuses on security controls like image integrity (digest pinning), privilege reduction (non-root user), and attack surface minimization (multi-stage builds), not merely build hygiene.

Detailed technical explanation

How to think about this question

Multi-stage builds (Option E) allow you to separate build-time dependencies from the runtime environment, resulting in a final image that contains only the necessary binaries and libraries, drastically reducing the attack surface. The USER directive (Option C) enforces that the container runs with a non-root user, which limits the impact of a container escape because the process lacks privileges to modify system files or perform privileged operations. Under the hood, Docker uses Linux capabilities and user namespaces, but specifying a non-root user in the Dockerfile ensures that even if a capability is dropped, the process identity is already restricted.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A practitioner preparing for the CKS exam encounters this exact type of scenario on the job. The correct answer here is not the most general option — it is the best answer for the specific constraint described. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Real exam questions reward reading the full scenario before eliminating options, because the constraint defines which answer fits.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related CKS practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free CKS practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this CKS question test?

Supply Chain Security — This question tests Supply Chain Security — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: Pin base image versions using SHA256 digests — Option B is correct because pinning base image versions using SHA256 digests ensures immutability and prevents the image from being silently updated to a potentially vulnerable version. Docker image tags (e.g., `ubuntu:latest`) are mutable and can point to different images over time, but a digest (e.g., `ubuntu@sha256:abc123...`) uniquely identifies a specific image manifest, guaranteeing that every build uses the exact same base image. This practice is a key supply chain security control to avoid dependency confusion or accidental inclusion of compromised base images.

What should I do if I get this CKS question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Are there clue words in this question I should notice?

Yes — watch for: "best". Signals that multiple options may be partially correct. Choose the option that most directly solves the exact problem described, not the one that sounds most complete.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

4 more ways this is tested on CKS

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. Which of the following is a best practice when writing a Dockerfile for a containerized application?

easy
  • A.Run the application as the root user for file permissions
  • B.Use a minimal base image such as distroless or alpine
  • C.Hardcode credentials in the Dockerfile for convenience
  • D.Use the latest tag for the base image to get the newest features

Why B: Using a minimal base image like distroless or alpine reduces the attack surface by eliminating unnecessary packages, libraries, and utilities that could be exploited. This aligns with the principle of least privilege and minimizes the number of Common Vulnerabilities and Exposures (CVEs) in the container, which is critical for supply chain security in Kubernetes environments.

Variation 2. Which of the following is a best practice for securing a Dockerfile?

easy
  • A.Hardcode API keys as environment variables
  • B.Use a minimal base image like alpine
  • C.Run the container as root to avoid permission issues
  • D.Use the latest tag for all images

Why B: Using a minimal base image like Alpine reduces the attack surface by including only essential packages and libraries, minimizing the number of potential vulnerabilities. This aligns with the principle of least functionality and is a key supply chain security practice for container images.

Variation 3. Which TWO are best practices for Dockerfile security? (Select 2)

medium
  • A.Use a non-root user
  • B.Use a minimal base image (distroless)
  • C.Store secrets in environment variables
  • D.Install SSH server for debugging
  • E.Run the container as root

Why A: Option A is correct because running containers as a non-root user reduces the risk of privilege escalation attacks. If an attacker compromises the container, they will not have root privileges, limiting their ability to modify system files or escape the container. This is enforced by using the USER directive in the Dockerfile to specify a non-root UID (e.g., USER 1001).

Variation 4. Which THREE of the following are best practices for writing Dockerfiles?

easy
  • A.Minimize the number of layers
  • B.Use the 'latest' tag for base images
  • C.Use specific tags or digests for base images
  • D.Install all packages that might be needed for debugging
  • E.Run containers as a non-root user

Why A: Minimizing the number of layers is a best practice because each instruction in a Dockerfile creates a new layer, and layers are stored and transferred as part of the image. Fewer layers reduce the overall image size, improve build and push/pull performance, and decrease the attack surface by limiting the number of intermediate filesystem snapshots that could contain sensitive data or cached artifacts.

Keep practising

More CKS practice questions

Last reviewed: Jul 4, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This CKS practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CKS exam.