Courseiva

CCNA Container Image Building Questions

53 questions · Container Image Building topic · All types, answers revealed

1
MCQmedium

An administrator needs to execute multiple commands in a single RUN instruction to minimize image layers. Which syntax is standard in a Containerfile?

A.RUN ["dnf update -y", "dnf install -y httpd"]
B.RUN { dnf update -y; dnf install -y httpd; }
C.RUN dnf update -y dnf install -y httpd
D.RUN dnf update -y && dnf install -y httpd
AnswerD

Chaining with `&&` executes both commands within one RUN instruction, producing a single image layer and satisfying the layer-minimisation constraint. The shell only proceeds to `dnf install` if `dnf update` succeeds, so failures halt the build rather than silently continuing. This is standard Containerfile syntax.

Why this answer

Combining commands using shell operators like && within a single RUN instruction reduces the total number of layers.

2
Multi-Selecteasy

Which TWO commands can be used with Podman to build a container image from a Containerfile? (Choose two.)

Select 2 answers
A.podman container build
B.podman image build
C.podman make image
D.podman create build
E.podman build
AnswersB, E

`podman image build` is the fully qualified form of the build command, invoking Buildah's image-building engine to read a Containerfile and produce a local image. It satisfies the stem's requirement for a valid Podman build command, functioning identically to `podman build` but with the explicit `image` subcommand namespace.

Why this answer

podman build and podman image build are both valid commands for building images.

3
MCQeasy

You need to set a persistent environment variable named 'APP_PORT' with the value '8080' inside a container image via the Containerfile. Which instruction should you use?

A.EXPORT APP_PORT=8080
B.ENV APP_PORT=8080
C.VAR APP_PORT=8080
D.SET APP_PORT=8080
AnswerB

ENV sets a persistent environment variable that remains available to processes at build and runtime within the image. Unlike ARG, which applies only during the build, ENV satisfies the requirement for a persistent APP_PORT value of 8080 in the Containerfile.

Why this answer

The ENV instruction in a Containerfile sets a persistent environment variable that is available both during the build and at container runtime. This is the standard Dockerfile/Containerfile directive for environment variables, and it persists in the image metadata. Options like EXPORT, VAR, or SET are not valid Containerfile instructions.

Exam trap

EX188 often tests the difference between build-time ARG and runtime ENV, and candidates mistakenly choose shell commands like EXPORT or non-existent instructions like SET or VAR.

How to eliminate wrong answers

Option A is wrong because EXPORT is a shell command, not a Containerfile instruction; it would not persist in the image. Option C is wrong because VAR is not a Containerfile instruction in any container build specification. Option D is wrong because SET is not a valid Containerfile instruction; it is used in Windows batch scripting, not container builds.

4
MCQmedium

You are building an image behind a corporate firewall that requires a custom Certificate Authority (CA) certificate to trust internal registries and repositories. How can you add this CA certificate to the build container?

A.TRUST corporate-ca.crt
B.EXPOSE CERT corporate-ca.crt
C.COPY corporate-ca.crt /etc/pki/ca-trust/source/anchors/ RUN update-ca-trust
D.ENV CA_CERT=corporate-ca.crt
AnswerC

Placing the CA in /etc/pki/ca-trust/source/anchors/ and running update-ca-trust regenerates the consolidated trust store, so the container trusts the internal registries and repositories required behind the corporate firewall. This satisfies the stem's custom CA constraint by installing the certificate into the system trust bundle at build time.

Why this answer

Placing the CA certificate in the appropriate system directory (e.g., /etc/pki/ca-trust/source/anchors/ on RHEL/Fedora-based images) and running update-ca-trust is standard.

5
MCQhard

You are building a minimal container image from scratch using 'FROM scratch'. Your statically compiled Go binary fails to execute when the container starts, with a 'file not found' error, even though it was successfully copied into the image. What is the most likely cause?

A.The binary was copied with incorrect permissions; it needs to be made executable with chmod +x during build.
B.The EXPOSE instruction was missing, preventing the binary from binding to network interfaces.
C.The WORKDIR instruction was omitted, preventing Podman from locating the binary.
D.The binary was dynamically linked against glibc or requires system files (like /etc/passwd or /lib64/ld-linux-x86-64.so.2) that are absent in the scratch image.
AnswerD

A scratch image contains no libraries or system files, so a dynamically linked binary cannot resolve its interpreter or glibc dependencies at runtime, producing 'file not found'. Statically compiling the Go binary with CGO disabled removes those external dependencies.

Why this answer

'FROM scratch' is an empty image. If the binary depends on shared libraries (e.g., glibc) or dynamic linkers that exist in the host/build environment but not in scratch, it will fail.

6
MCQmedium

What is the primary benefit of utilizing multi-stage builds in Containerfiles?

A.It allows you to produce a final production image containing only the application binary and runtime dependencies, significantly reducing image size and attack surface.
B.It automatically encrypts environment variables stored in the image layers.
C.It bypasses the need for a container registry when sharing images.
D.It speeds up local DNS resolution during container execution.
AnswerA

Multi-stage builds let earlier stages compile and build, while the final stage copies only the binary and required runtime libraries. Build tools, source and caches are excluded, shrinking the production image and reducing its exploitable attack surface.

Why this answer

Multi-stage builds allow developers to use multiple FROM statements, leaving behind build tools and heavy SDKs in earlier stages and keeping production images small and secure.

7
Multi-Selectmedium

Which TWO instructions can be used to copy files or directories from a build context into a container image?

Select 2 answers
A.PULL
B.INSTALL
C.COPY
D.ADD
E.GET
AnswersC, D

COPY transfers files or directories from the build context into the image filesystem, without ADD's URL fetching or tar auto-extraction. It satisfies the stem's requirement for an instruction that copies build-context content into the container image.

Why this answer

The COPY instruction is correct because it copies files or directories from the build context (or a stage in a multi-stage build) into the image filesystem, with the syntax COPY <src>... <dest>, and it performs no automatic extraction or remote URL fetching. The ADD instruction is also correct because it likewise copies files or directories from the build context into the image, and additionally supports remote URLs and auto-extraction of local tar archives, though for plain copying COPY is preferred. PULL is not a Dockerfile instruction for transferring build-context files into an image; it describes fetching an image from a registry (docker pull).

INSTALL is not a Dockerfile instruction; package installation is done via RUN with a package manager such as apt-get or yum. GET is not a Dockerfile instruction for copying build-context content into an image.

Exam trap

EX188 often tests the distinction between COPY and ADD, and candidates may forget that both can copy files, but only ADD has extra features; they might incorrectly exclude COPY or include invalid instructions like PULL.

8
Multi-Selecthard

Which THREE statements correctly describe the differences between CMD and ENTRYPOINT in a Containerfile?

Select 3 answers
A.ENTRYPOINT instructions cannot be overridden at runtime under any circumstances.
B.Combining ENTRYPOINT and CMD allows default arguments to be supplied while retaining override flexibility.
C.ENTRYPOINT allows configuring an image that runs as a specific dedicated executable.
D.CMD arguments can be easily overridden by arguments passed to 'podman run'.
E.CMD and ENTRYPOINT perform identical functions with no syntactical differences.
AnswersB, C, D

ENTRYPOINT fixes the executable, while CMD supplies default arguments that a user can override at runtime by appending values to `podman run`. This pairing satisfies the stem's requirement for defaults with override flexibility, unlike CMD alone, which is fully replaced when arguments are passed.

Why this answer

Option B is correct because when both ENTRYPOINT and CMD are used together, CMD supplies default arguments to the ENTRYPOINT executable, and those defaults can still be replaced by arguments passed at runtime to podman run. Option C is correct because ENTRYPOINT is specifically designed to set the image's main executable, making the container behave like a dedicated command such as /usr/bin/httpd or a custom application binary. Option D is correct because CMD provides defaults that are easily overridden: any arguments appended to podman run replace the CMD instruction entirely.

Option A is incorrect because ENTRYPOINT can be overridden at runtime using podman run --entrypoint. Option E is incorrect because CMD and ENTRYPOINT serve different roles and have distinct syntax and behavior, especially regarding how runtime arguments interact with them.

Exam trap

EX188 often tests the misconception that ENTRYPOINT is immutable or that CMD and ENTRYPOINT are interchangeable, when in fact ENTRYPOINT can be overridden with --entrypoint and CMD only supplies defaults.

9
Multi-Selectmedium

Which TWO of the following instructions in a Containerfile can be written using either the shell form or the exec form?

Select 2 answers
A.WORKDIR
B.RUN
C.FROM
D.CMD
E.ENV
AnswersB, D

RUN accepts both forms: shell form executes via `/bin/sh -c`, while exec form runs the command directly without a shell. This satisfies the stem's requirement for instructions supporting either syntax, since RUN genuinely permits both, unlike CMD or ENTRYPOINT where the distinction affects signal handling and argument passing.

Why this answer

Option B (RUN) is correct because the RUN instruction supports both the shell form (e.g., RUN apt-get update) and the exec form (e.g., RUN ["apt-get", "update"]), allowing either a shell command string or a JSON array of executable and arguments. Option D (CMD) is correct because CMD likewise accepts both forms: the shell form (CMD echo hello) and the exec form (CMD ["echo", "hello"]), with the exec form being the preferred default-command syntax. Option A (WORKDIR) is not correct because it takes only a plain path argument (WORKDIR /app) and has no exec/shell form distinction.

Option C (FROM) is not correct because it specifies an image reference and optional stage name (FROM alpine:3.19 AS build) with no shell or exec form. Option E (ENV) is not correct because it sets variables using key=value syntax (ENV KEY=value) and does not offer an exec-form JSON array variant.

Exam trap

EX188 often tests the misconception that all Containerfile instructions support both shell and exec forms, but only RUN, CMD, and ENTRYPOINT do; candidates may incorrectly include WORKDIR or ENV.

10
Multi-Selectmedium

You are reviewing a Containerfile for a web application. The Containerfile currently uses the shell form for its ENTRYPOINT instruction. You want to ensure that the application receives signals correctly and that arguments passed to `podman run` are properly forwarded to the application. Which TWO changes should you make? (Choose two.)

Select 2 answers
A.Change the ENTRYPOINT instruction to use the exec form (JSON array).
B.Use the VOLUME instruction to declare a directory for application data.
C.Use the CMD instruction to provide default arguments to the ENTRYPOINT.
D.Add a HEALTHCHECK instruction to monitor the application.
E.Add a SHELL instruction to set /bin/bash as the default shell.
AnswersA, C

The exec form runs the executable directly without a shell, allowing it to receive signals like SIGTERM from Podman and forward arguments correctly. This is critical for graceful shutdown and proper argument handling. The shell form wraps the command in /bin/sh -c, which can interfere with signal propagation and argument forwarding, so switching to exec form is a best practice.

Why this answer

To ensure proper signal handling and argument forwarding, the ENTRYPOINT should use the exec form, which runs the process directly without a shell wrapper. Additionally, using CMD to provide default arguments allows runtime arguments to override them, ensuring they are passed to the application. Together, these changes make the container behave correctly when receiving signals and arguments.

Exam trap

The trap here is assuming that the shell form of ENTRYPOINT can handle signals and arguments as well as the exec form, when the shell wrapper can swallow signals and complicate argument passing.

11
MCQeasy

Which instruction documents the network ports on which a container listens at runtime?

A.LISTEN
B.EXPOSE
C.PORT
D.OPEN
AnswerB

EXPOSE documents the network ports a container listens on at runtime, functioning as metadata for image consumers and tooling. It satisfies the stem's requirement for declaring listening ports, unlike RUN or CMD, which execute commands rather than record port information.

Why this answer

The EXPOSE instruction in a Containerfile documents the network port(s) the containerized application listens on at runtime. It is metadata only — it does not actually publish the port to the host; that requires -p or -P at podman run time. EXPOSE is the standard OCI/Dockerfile directive for this purpose and is what tools like podman inspect read to report exposed ports.

Exam trap

EX188 often tests the confusion between EXPOSE (build-time documentation of a port) and -p/-P (runtime publishing), catching candidates who think EXPOSE actually opens the port on the host.

How to eliminate wrong answers

Option A is wrong because LISTEN is not a valid Containerfile instruction — it is a SQL/network socket concept, not an image build directive. Option C is wrong because PORT is not a Containerfile instruction; port mapping is done at runtime with -p, not declared with a PORT keyword. Option D is wrong because OPEN is not a Containerfile instruction and has no meaning in image builds.

12
Multi-Selecthard

Which THREE practices should be observed when managing environment variables (ENV vs ARG) in Containerfiles for secure and efficient builds? (Choose three.)

Select 3 answers
A.Use 'ENV' for configuration parameters that the application needs to read during container runtime.
B.Use 'ARG' for variables that are only needed during the build process and should not persist in the final image metadata.
C.Ensure that 'ENV' variables defined in earlier stages automatically carry over into subsequent multi-stage build stages without re-declaration.
D.Declare 'ARG' instructions before the first 'FROM' instruction if they are to be used in global FROM scoping (e.g., base image parameterization).
E.Use 'ENV' for passing secret API tokens so they are automatically encrypted in the image layers.
AnswersA, B, D

ENV values are baked into the image configuration and exported to the container's process environment at runtime, so the application can read configuration such as database hosts without rebuilds. ARG would not survive into the running container.

Why this answer

Option A is correct because ENV variables are baked into the image configuration and are available to the application at runtime, making them the right choice for runtime configuration parameters. Option B is correct because ARG values exist only during the build and, unlike ENV, are not persisted in the final image metadata, so build-only values should use ARG. Option D is correct because an ARG declared before the first FROM is in the global scope and can be referenced in FROM instructions (e.g., ARG BASE=alpine then FROM ${BASE}), enabling base image parameterization.

Option C is not correct because ENV variables do not automatically carry over between separate stages in a multi-stage build; each stage starts from its own base and must re-declare or explicitly inherit values. Option E is not correct because ENV values are stored in plaintext in image layers and metadata, so they must never be used for secrets such as API tokens.

Exam trap

EX188 often tests the misconception that ENV variables propagate across multi-stage build stages automatically and that ENV encrypts secrets — both are false and lead candidates to select the wrong options.

13
Multi-Selectmedium

Which THREE directives or practices are associated with implementing secure container builds and adhering to least-privilege principles? (Choose three.)

Select 3 answers
A.Hardcoding database passwords directly into ENV instructions so the application can read them easily.
B.Using minimal, trusted base images to reduce the total software footprint and vulnerability surface.
C.Adding a 'USER' instruction with a non-root UID/username before defining the runtime CMD or ENTRYPOINT.
D.Running all RUN instructions with '--privileged' inside the Containerfile.
E.Using build-time secrets with '--secret' mounts rather than baking credentials into image layers.
AnswersB, C, E

Minimal trusted base images shrink the installed package set, directly reducing the vulnerability surface and satisfying least privilege by removing unnecessary software. Fewer components mean fewer exploitable paths and less to patch, which is the mechanism that limits attacker opportunity.

Why this answer

Option B is correct because starting from minimal, trusted base images (e.g., distroless, alpine, or scratch) shrinks the installed package set and attack surface, reducing the number of exploitable CVEs in the final image. Option C is correct because a USER instruction that switches to a non-root UID/username before CMD or ENTRYPOINT enforces least privilege at runtime, preventing container processes from having root capabilities if the container is compromised. Option E is correct because BuildKit's --secret mounts (e.g., RUN --mount=type=secret) inject credentials only during the build step without persisting them in any image layer, unlike ENV or COPY which bake secrets permanently into the image history.

Option A is wrong because hardcoding database passwords in ENV instructions stores credentials in plaintext in image metadata and layers, violating least privilege and secret-management best practices. Option D is wrong because running RUN instructions with --privileged grants the build container full host capabilities, which is the opposite of least privilege and dramatically increases the risk of container escape during builds.

Exam trap

EX188 often tests the misconception that ENV or ARG is an acceptable place for secrets, when in fact only BuildKit secret mounts keep credentials out of image layers.

14
MCQhard

You are optimizing a Containerfile using multi-stage builds to minimize image size. What is the key advantage of a multi-stage build in Podman?

A.It automatically converts Dockerfiles into systemd service units.
B.It allows you to copy only finalized artifacts from a heavy build stage into a minimal production stage.
C.It enables building container images concurrently across multiple remote container registries.
D.It eliminates the need for caching layers during the podman build process.
AnswerB

Multi-stage builds let earlier stages carry compilers, SDKs and build dependencies, while the final stage copies only the finished artefacts. This keeps the production image minimal, since heavyweight build tooling never ships in the runtime layer, directly reducing image size.

Why this answer

Multi-stage builds let you use multiple FROM instructions in a single Containerfile, where earlier stages can contain heavy build tools and dependencies, and the final stage copies only the compiled artifacts (binaries, static files) from the build stage. This dramatically reduces the final image size because compilers, SDKs, and intermediate files are discarded. The COPY --from=<stage> instruction is the key mechanism enabling this selective transfer.

Exam trap

EX188 often tests whether candidates confuse multi-stage builds with image distribution or caching features, when the core purpose is simply copying finalized artifacts from a heavy build stage into a minimal runtime stage.

How to eliminate wrong answers

Option A is wrong because multi-stage builds have nothing to do with systemd unit generation; Podman can generate systemd units via `podman generate systemd`, but that is unrelated to multi-stage builds. Option C is wrong because multi-stage builds do not enable concurrent builds across remote registries; they are a Containerfile authoring technique for reducing image size, not a distribution or parallelism feature. Option D is wrong because multi-stage builds do not eliminate layer caching — each stage still benefits from layer caching, and in fact caching behavior across stages is an important consideration, not something multi-stage builds remove.

15
MCQhard

When using the ADD instruction with a remote URL source, what is a recommended best practice regarding security and layer efficiency?

A.Always use ADD for remote URLs because it automatically verifies SSL/TLS certificates against the host system store.
B.ADD for remote URLs is deprecated and will cause podman build to abort with an error.
C.Avoid ADD for remote URLs; instead, use curl or wget within a RUN instruction to download, extract, and clean up in a single layer.
D.Use ADD for remote URLs because it creates a smaller layer than RUN.
AnswerC

Using curl/wget in a RUN instruction gives granular control over downloads, headers, and cache handling.

Why this answer

Using ADD with a remote URL is discouraged because it creates a separate layer for the downloaded file and does not automatically extract archives (unless the URL points to a recognized archive format, but that behavior is inconsistent). Instead, using curl or wget within a RUN instruction allows you to download, extract, and clean up in a single layer, reducing image size and avoiding caching issues. This is a security best practice because you can verify checksums and avoid leaving unnecessary files.

Exam trap

EX188 often tests the difference between ADD and COPY, and candidates mistakenly believe ADD is preferred for remote URLs due to convenience, ignoring layer efficiency and security.

How to eliminate wrong answers

Option A is wrong because ADD does not automatically verify SSL/TLS certificates against the host system store; it relies on the container's CA certificates, which may be outdated or missing. Option B is wrong because ADD for remote URLs is not deprecated; it still works but is discouraged. Option D is wrong because ADD for remote URLs creates an additional layer for the downloaded file, which can increase image size, not decrease it.

16
MCQeasy

You want to set the working directory for any subsequent RUN, CMD, ENTRYPOINT, COPY, and ADD instructions that follow it in the Containerfile. Which instruction achieves this?

A.DIR
B.WORKDIR
C.CD
D.PATH
AnswerB

WORKDIR sets the working directory for subsequent RUN, CMD, ENTRYPOINT, COPY and ADD instructions, satisfying the stem's requirement to affect all following instructions. Unlike cd inside a single RUN, it persists across build stages and layers, so later instructions resolve relative paths from that directory.

Why this answer

The WORKDIR instruction sets the working directory for subsequent RUN, CMD, ENTRYPOINT, COPY, and ADD instructions in a Containerfile. If the directory does not exist, WORKDIR creates it automatically, and it can be used multiple times to change context throughout the build.

Exam trap

The trap is picking CD because it is the familiar shell command for changing directories — candidates forget that Containerfile instructions are a distinct DSL and CD is not part of it.

How to eliminate wrong answers

Option A is wrong because DIR is not a valid Containerfile instruction — it is a Windows command shell builtin, not a Dockerfile/Containerfile directive. Option C is wrong because CD is a shell command, not a Containerfile instruction; it cannot be used to set build-time working directory. Option D is wrong because PATH is an environment variable, not an instruction, and it controls executable lookup, not the working directory.

17
MCQhard

You need to ensure that a container image built with Podman includes reproducible timestamps for files to improve security and supply chain verification. Which flag or environment variable controls this?

A.PODMAN_REPRODUCIBLE_BUILD=true
B.TIMESTAMP=0 in the Containerfile ENV
C.--reproducible flag in podman build
D.SOURCE_DATE_EPOCH
AnswerD

SOURCE_DATE_EPOCH sets a fixed Unix timestamp that Podman's build tooling applies to file metadata, replacing build-time clocks. This yields byte-identical layers across rebuilds, satisfying the reproducibility constraint and enabling deterministic image digests for supply chain verification.

Why this answer

SOURCE_DATE_EPOCH is the standardized environment variable (from the reproducible-builds.org specification) that sets a fixed timestamp for files created during a build, enabling bit-for-bit reproducible images. Podman and Buildah honor it during podman build, so setting it produces deterministic file timestamps. This supports supply chain verification because identical inputs yield identical image digests.

Exam trap

EX188 often tests whether candidates know the standardized reproducible-build variable versus invented flags, so candidates who guess a plausible-sounding --reproducible flag or PODMAN_* variable pick A or C.

How to eliminate wrong answers

Option A is wrong because PODMAN_REPRODUCIBLE_BUILD is not a real Podman environment variable; no such flag exists in Podman's documentation. Option B is wrong because setting TIMESTAMP=0 in a Containerfile ENV only defines an application-level variable and does not control how the build engine stamps files. Option C is wrong because podman build has no --reproducible flag; reproducibility is achieved via SOURCE_DATE_EPOCH and related build practices, not a dedicated CLI switch.

18
Multi-Selecthard

Which THREE behaviors occur when utilizing multi-stage builds in a Containerfile? (Choose three.)

Select 3 answers
A.You can include multiple 'FROM' instructions in a single Containerfile, where each 'FROM' starts a new stage of the build.
B.All intermediate stages are automatically tagged and pushed to the local registry when the build completes.
C.You can assign a name to a build stage using the 'AS stage_name' syntax on the FROM instruction.
D.Artifacts from earlier stages are automatically merged into the final image layers unless explicitly deleted.
E.You can use 'COPY --from=<stage_name>' to pull compiled artifacts from a previous stage into the current stage.
AnswersA, C, E

Each FROM instruction begins a fresh build stage with its own base image and filesystem layer, so a single Containerfile can chain several stages. This satisfies the multi-stage requirement that stages remain isolated until explicitly copied between.

Why this answer

Multi-stage builds allow multiple FROM lines, naming stages, and selective copying between them.

19
Multi-Selecteasy

Which TWO instructions are used to define variables or set environment values within a Containerfile? (Choose two.)

Select 2 answers
A.DEFINE
B.VAR
C.ARG
D.ENV
E.SET
AnswersC, D

ARG declares build-time variables that are available only during the image build, not at container runtime. This satisfies the stem's requirement to define variables within a Containerfile, since ARG instructions set values consumed by subsequent build steps such as RUN, without persisting into the running container's environment.

Why this answer

ARG and ENV are used for defining build arguments and environment variables respectively.

20
MCQeasy

You are writing a Containerfile to build a custom application image using podman build. Which instruction should you use as the mandatory first non-comment instruction to define the base image?

A.IMPORT
B.FROM
C.BASE
D.INIT
AnswerB

FROM specifies the base image that subsequent Containerfile instructions build upon, and it must be the first non-comment instruction in a valid Containerfile. This satisfies the stem's requirement, because podman build cannot construct a layered image without an initial parent image reference.

Why this answer

The FROM instruction is the mandatory first non-comment instruction in a Containerfile (or Dockerfile) because it specifies the base image upon which subsequent instructions operate. Without FROM, the build cannot determine the starting filesystem and will fail. It sets the stage for all following layers, such as RUN, COPY, and CMD.

Exam trap

EX188 often tests the misconception that other keywords like BASE or IMPORT can define the base image, but only FROM is valid; candidates might confuse Docker commands with Containerfile instructions.

How to eliminate wrong answers

Option A is wrong because IMPORT is not a valid Containerfile instruction; it is a Docker command (docker import) for creating an image from a tarball, not a build instruction. Option C is wrong because BASE is not a recognized instruction in Containerfile syntax; the correct keyword is FROM. Option D is wrong because INIT is not a Containerfile instruction; it might be confused with init processes in containers, but it has no role in defining the base image.

21
MCQeasy

You need to define a persistent environment variable named 'PORT' with the value '8080' that is available during both the build process and when running containers from the resulting image. Which instruction should you use?

A.SET
B.ENV
C.VAR
D.EXPORT
AnswerB

ENV sets a persistent environment variable that remains in the image metadata, so it is available both during subsequent build steps and at container runtime. This directly satisfies the stem's requirement for a variable present across build and run, unlike ARG, which exists only at build time.

Why this answer

The ENV instruction in a Containerfile/Dockerfile sets an environment variable that persists both during subsequent build steps (RUN) and in the final image at runtime. Using ENV PORT=8080 makes PORT available to any process started from the resulting image, satisfying the requirement for build-time and runtime availability.

Exam trap

EX188 often tests the distinction between ENV (persists to runtime) and ARG (build-time only), and includes fabricated instructions like SET, VAR, or EXPORT to catch candidates who guess based on shell familiarity.

How to eliminate wrong answers

Option A is wrong because SET is not a valid Containerfile/Dockerfile instruction — it does not exist in the OCI image build spec. Option C is wrong because VAR is not a valid instruction; there is no VAR directive in Containerfile syntax. Option D is wrong because EXPORT is a shell builtin, not a Containerfile instruction — while you could use RUN export PORT=8080, that only affects the single RUN layer's shell and does not persist to the image or runtime.

22
MCQeasy

Which instruction should be used in a Containerfile to copy local files from the host machine into the container filesystem?

A.COPY
B.TRANSFER
C.ADD
D.MOVE
AnswerA

COPY transfers files from the build context on the host into the image filesystem during a build. ADD also copies but additionally handles remote URLs and archive extraction, so COPY is the precise instruction for plain local file transfer into the container.

Why this answer

The `COPY` instruction in a Containerfile is used to copy files from the build context (host machine) into the container filesystem. It is the standard and recommended instruction for this purpose.

Exam trap

EX188 often tests the difference between `COPY` and `ADD`, and candidates may incorrectly choose `ADD` for simple file copying or invent instructions like `TRANSFER` or `MOVE`.

How to eliminate wrong answers

Option B is wrong because `TRANSFER` is not a valid Containerfile instruction. Option C is wrong because `ADD` is also used to copy files, but it has additional features like extracting tar archives and fetching remote URLs; however, `COPY` is the preferred instruction for simple file copying. Option D is wrong because `MOVE` is not a valid Containerfile instruction.

23
MCQmedium

A developer builds a custom image with `podman build -t app:v1 .` but repeatedly gets stale results because an earlier RUN layer that installs packages is cached, even though the repository metadata has changed. The developer wants to force podman to ignore all cached layers for the next build without deleting the local image or build cache. Which command accomplishes this?

A.podman build --pull=always -t app:v1 .
B.podman build --no-cache -t app:v1 .
C.podman build --layers=false -t app:v1 .
D.podman rmi app:v1 && podman build -t app:v1 .
AnswerB

The --no-cache flag tells podman to bypass the layer cache entirely and execute every instruction in the Containerfile from scratch, producing fresh layers even for unchanged instructions. It does not delete the local image or the stored cache; it simply instructs this build to avoid reusing cached layers, so the newly fetched repository metadata is honored during the RUN that installs packages.

Why this answer

The scenario is about stale cached layers during a build. The --no-cache flag is the documented podman build option that instructs podman to ignore the layer cache for that build and execute every Containerfile instruction fresh, which is exactly what is needed to pick up new repository metadata without deleting the local image or the cache store.

Exam trap

The trap here is assuming that removing the local image also clears the intermediate build cache layers, when in fact podman keeps cached layers separately and they can still be reused.

24
Multi-Selectmedium

Which THREE practices should be followed to optimize container image size and build caching when writing Containerfiles? (Choose three.)

Select 3 answers
A.Order Containerfile instructions from least frequently changing to most frequently changing to maximize cache hits.
B.Combine package installation and cache cleanup in a single RUN instruction to prevent cache retention across layers.
C.Avoid using .containerignore files so that all host files are always cached by Podman.
D.Use multi-stage builds to separate build-time dependencies from the final runtime image.
E.Install all debugging tools and heavy development SDKs in the final production stage.
AnswersA, B, D

Placing base dependencies before source code maximizes cache reuse.

Why this answer

Caching and layer minimization depend on instruction order, cleanup in the same layer, and avoiding unnecessary tool installation.

25
MCQhard

You are building an image with a multi-stage Containerfile. The final stage uses `FROM registry.access.redhat.com/ubi9/ubi-minimal` and you want to copy only the compiled binary from a builder stage named `builder` into `/usr/local/bin/app`. Which Containerfile line correctly copies that artifact?

A.RUN cp --from=builder /src/app /usr/local/bin/app
B.COPY --from=0 /src/app /usr/local/bin/app
C.ADD --stage=builder /src/app /usr/local/bin/app
D.COPY --from=builder /src/app /usr/local/bin/app
AnswerD

The COPY instruction supports the --from flag, which references a previous build stage by its name or index. Here, `builder` is the named stage, so COPY --from=builder pulls the compiled artifact from that stage's filesystem into the final image. This keeps the final image minimal because only the binary is transferred, not the entire build toolchain.

Why this answer

Multi-stage builds let you copy artifacts from a named or indexed earlier stage using COPY --from=<stage>. Because the scenario names the stage `builder`, the correct line references that name. This transfers only the compiled binary into the minimal final image, keeping the runtime image small and free of build tooling.

Exam trap

The trap here is confusing the --from flag (a COPY feature for referencing build stages) with an imaginary --stage flag or with runtime shell commands.

26
Multi-Selecthard

Which THREE statements accurately describe the differences between shell form and exec form for CMD and ENTRYPOINT instructions? (Choose three.)

Select 3 answers
A.Shell form is mandatory when using multi-stage builds.
B.Exec form allows shell variable expansion (like $VAR) directly without needing explicit shell invocation.
C.Exec form ensures that Unix signals (such as SIGTERM) sent by Podman are received directly by the application process as PID 1.
D.Exec form is written using JSON array syntax (e.g., ["executable", "param"]).
E.Shell form automatically wraps the command with '/bin/sh -c', which causes the application to run as a child process rather than PID 1.
AnswersC, D, E

In exec form the executable becomes PID 1 directly, so signals such as SIGTERM sent by Podman reach the application itself. This enables correct signal handling and graceful termination, unlike shell form where a shell intercepts them.

Why this answer

Option C is correct because in exec form the specified executable is launched directly as PID 1, so signals like SIGTERM sent by Podman (or Docker) are delivered straight to the application, enabling proper graceful shutdown. Option D is correct because exec form uses JSON array syntax such as ["executable", "param"], which is the defining syntactic characteristic of exec form in CMD and ENTRYPOINT instructions. Option E is correct because shell form implicitly wraps the command with '/bin/sh -c', so the shell becomes PID 1 and the actual application runs as a child process, which can prevent it from receiving signals directly.

Option A is incorrect because shell form is not mandatory in multi-stage builds; both shell and exec forms work in any build stage. Option B is incorrect because exec form does not perform shell variable expansion of things like $VAR unless you explicitly invoke a shell (e.g., ["/bin/sh", "-c", "echo $VAR"]); it is shell form that provides implicit variable expansion.

Exam trap

EX188 often tests the nuances of shell vs exec form, and candidates may incorrectly believe that exec form supports shell variable expansion or that shell form is required for multi-stage builds.

27
MCQmedium

You are using a multi-stage build in your Containerfile. How do you copy a compiled binary named 'app' from a build stage named 'builder' into your final production runtime stage?

A.COPY --stage=builder /app /app
B.ADD --stage-name=builder /app /app
C.IMPORT --from=builder /app /app
D.COPY --from=builder /app /app
AnswerD

The COPY --from=builder instruction pulls artefacts from the named earlier build stage rather than the build context, copying the compiled binary at /app into the final runtime image. This satisfies the multi-stage requirement to exclude build tooling from production.

Why this answer

The COPY instruction in a Containerfile supports the --from=<stage> flag, which references a previously named build stage (e.g., 'builder') and copies artifacts from that stage's filesystem into the current stage. This is the canonical multi-stage build pattern for producing slim runtime images that exclude compilers, SDKs, and build dependencies. The syntax COPY --from=builder /app /app copies the compiled binary from the builder stage's /app path into the final stage's /app path.

Exam trap

EX188 often tests Containerfile instruction syntax, and candidates confuse COPY flags with Docker Compose or Kubernetes keywords, or assume ADD is the general-purpose copy instruction when COPY is the correct one for cross-stage copies.

How to eliminate wrong answers

Option A is wrong because --stage is not a valid COPY flag; the correct flag is --from, and using --stage would cause a build error. Option B is wrong because ADD does not support a --stage-name flag, and ADD is intended for URL/tarball retrieval rather than cross-stage copying. Option C is wrong because IMPORT is not a Containerfile instruction at all — it is not part of the Dockerfile/Containerfile specification.

28
MCQhard

You are optimizing a Containerfile for a Python application. The build currently uses a single RUN instruction that installs dependencies, runs tests, and cleans up temporary files. You want to leverage build caching to speed up rebuilds when only application code changes, while ensuring that dependency installation is cached separately. Which approach best achieves this?

A.Split the RUN instruction into multiple RUN instructions, placing the dependency installation before the COPY of application code.
B.Add a .containerignore file to exclude application code from the build context.
C.Use a multi-stage build where the first stage installs dependencies and the second stage copies them.
D.Keep the single RUN instruction but add a cache mount for the package manager.
AnswerA

This approach separates dependency installation from application code copying. Podman caches each instruction layer. Since dependencies change infrequently, their layer remains cached when only code changes, avoiding reinstallation. The COPY of code invalidates subsequent layers, but dependencies are already cached. This optimizes rebuild time and is a best practice for leveraging build caching effectively.

Why this answer

To optimize caching, dependencies should be installed in a layer that remains unchanged when application code changes. Placing dependency installation in a RUN instruction before COPYing the application code ensures that the dependency layer is cached and reused. Subsequent code changes only invalidate the COPY and later layers, not the dependency installation.

This minimizes rebuild time and is a common pattern in Containerfile optimization.

Exam trap

The trap here is thinking that a cache mount or multi-stage build alone solves caching for dependency installation, when the key is ordering instructions so that infrequently changed steps are cached before frequently changed code is copied.

29
Multi-Selecteasy

Which TWO Containerfile instructions are used to bring files or data from outside the container into the build context or image? (Choose two.)

Select 2 answers
A.COPY
B.GET
C.ADD
D.FETCH
E.IMPORT
AnswersA, C

COPY transfers files from the build context or a stage into the image filesystem, satisfying the requirement to bring external data in. ADD performs the same transfer with extra archive and URL handling. Both are distinct from RUN, which executes commands inside the build.

Why this answer

COPY is correct because it copies files or directories from the build context (or from a stage in a multi-stage build via --from) into the image filesystem, and it does not perform any remote URL fetching or automatic archive extraction. ADD is correct because it also brings files into the image, and additionally supports fetching remote URLs and auto-extracting recognized local tar archives into the destination. GET, FETCH, and IMPORT are not valid Containerfile/Dockerfile instructions, so they cannot be used to bring files or data into the build context or image.

Exam trap

EX188 often tests the confusion between COPY and ADD, and candidates may incorrectly assume GET, FETCH, or IMPORT are valid instructions because they sound like file-transfer verbs.

30
MCQhard

You are designing a container image that runs an executable web server. You want to provide default arguments to the executable that can be easily overridden by a user passing arguments directly to 'podman run'. Which instruction combination is best?

A.Use ENTRYPOINT for the binary and CMD for the default arguments.
B.Use ENV for the binary and WORKDIR for the arguments.
C.Use RUN for both the binary and the arguments.
D.Use CMD for the binary and ENTRYPOINT for the default arguments.
AnswerA

ENTRYPOINT fixes the executable, while CMD supplies default arguments that a user can replace by appending values to `podman run`. This satisfies the stem's requirement for overridable defaults, since arguments passed on the command line replace CMD entirely but leave ENTRYPOINT intact.

Why this answer

Using ENTRYPOINT for the binary and CMD for the default arguments is the best practice. When a user runs 'podman run <image> <args>', the arguments passed on the command line override the CMD instruction, while the ENTRYPOINT remains the executable. This allows the user to easily override default arguments without changing the binary.

Exam trap

EX188 often tests the interaction between ENTRYPOINT and CMD, and candidates may confuse which instruction provides the executable and which provides default arguments.

How to eliminate wrong answers

Option B is wrong because ENV is used to set environment variables, not to specify the executable, and WORKDIR sets the working directory, not arguments. Option C is wrong because RUN executes commands during image build, not at container runtime, and cannot be overridden by podman run arguments. Option D is wrong because it reverses the roles: CMD for the binary would make the binary the default command, but if ENTRYPOINT is used for arguments, it would be treated as the executable, which is incorrect.

31
MCQeasy

Which Containerfile instruction sets the working directory for any subsequent RUN, CMD, ENTRYPOINT, COPY, and ADD instructions?

A.PATH
B.ENV
C.WORKDIR
D.RUN
AnswerC

WORKDIR sets the working directory used by subsequent RUN, CMD, ENTRYPOINT, COPY and ADD instructions in the Containerfile, persisting across later layers. This directly satisfies the stem's requirement for the instruction that establishes that directory context.

Why this answer

The WORKDIR instruction sets the working directory for any instructions that follow it in the Containerfile.

32
MCQeasy

Which user instruction changes the user name or UID and group name or GID to use when running subsequent instructions in the Containerfile?

A.LOGIN
B.IDENTITY
C.USER
D.ACCOUNT
AnswerC

USER sets the user name, UID, group name and GID applied when running subsequent RUN, CMD and ENTRYPOINT instructions, plus the container's runtime identity. It changes execution identity only, not file ownership, which requires separate handling.

Why this answer

The USER instruction sets the user name or UID to use for running the image and for any RUN, CMD and ENTRYPOINT instructions that follow it.

33
MCQmedium

By default, podman build executes build instructions using the root user. You want to switch the execution context to a non-privileged user named 'appuser' for all subsequent RUN, CMD, and ENTRYPOINT instructions. Which instruction should you use?

A.USER
B.LOGIN
C.SU
D.ACCOUNT
AnswerA

The USER instruction sets the execution identity for subsequent RUN, CMD and ENTRYPOINT instructions within the image, satisfying the stem's requirement to switch from root to the non-privileged 'appuser' account. Unlike WORKDIR or ENV, USER changes the UID/GID context, so later build steps and container runtime processes run unprivileged.

Why this answer

The USER instruction in a Containerfile sets the UID (and optionally GID) that subsequent RUN, CMD, and ENTRYPOINT instructions execute as, and it also sets the default user for the running container. Placing USER appuser before the relevant instructions switches the execution context to that non-privileged account.

Exam trap

EX188 often tests whether candidates confuse Linux commands (su, login) with Containerfile instructions — only USER is a valid build directive for changing execution context.

How to eliminate wrong answers

Option B is wrong because LOGIN is not a valid Containerfile instruction — there is no such directive in the OCI/Dockerfile specification. Option C is wrong because SU is a Linux command, not a Containerfile instruction; you cannot use it as a build directive. Option D is wrong because ACCOUNT is not a Containerfile instruction — it is a fabricated keyword with no meaning to podman build.

34
Multi-Selectmedium

Which THREE features or characteristics distinguish the ADD instruction from the COPY instruction in a Containerfile? (Choose three.)

Select 3 answers
A.ADD can automatically extract local compressed tar archive files into the destination directory.
B.ADD requires the source file to be located within a git repository, unlike COPY.
C.COPY supports remote URLs natively just like ADD.
D.ADD supports fetching files directly from remote URLs.
E.COPY is generally recommended over ADD for simple file copying due to its predictable, transparent behavior.
AnswersA, D, E

ADD unpacks a recognised local compressed tar archive (gzip, bzip2 or xz) directly into the destination path, satisfying the stem's requirement for a distinguishing characteristic. COPY merely transfers files verbatim, performing no extraction, so archive handling is an axis unique to ADD.

Why this answer

Option A is correct because ADD automatically unpacks recognized local compressed tar archives (e.g., .tar, .tar.gz, .tgz, .tar.bz2, .tar.xz) into the destination directory, whereas COPY just places the file as-is. Option D is correct because ADD can fetch files directly from remote HTTP/HTTPS URLs, a capability COPY does not have. Option E is correct because COPY is preferred for straightforward file copying since its behavior is explicit and predictable, avoiding ADD's implicit extraction and remote-fetch side effects.

Option B is wrong because neither ADD nor COPY requires the source to be in a git repository. Option C is wrong because COPY does not support remote URLs natively; only ADD does.

Exam trap

EX188 often tests the misconception that COPY supports remote URLs like ADD, or that ADD requires git; the real distinctions are tar auto-extraction, URL fetch, and COPY's predictability.

35
Multi-Selecteasy

Which TWO statements are true regarding the EXPOSE instruction in a Containerfile? (Choose two.)

Select 2 answers
A.It informs Podman that the container listens on the specified network ports at runtime.
B.It replaces the need to define environment variables for port configuration.
C.It enforces strict firewall rules inside the container network namespace, blocking unexposed ports.
D.It acts as a type of documentation between the image creator and container operator.
E.It automatically publishes all exposed ports to random host ports without needing the -p or -P flag.
AnswersA, D

EXPOSE documents the ports the containerised process listens on, letting Podman and other tooling know which network ports are intended for publication. It satisfies the stem's requirement by declaring runtime listening intent as image metadata, though it does not itself publish the port or alter firewall rules.

Why this answer

Option A is correct because EXPOSE in a Containerfile declares the network ports the containerized application listens on at runtime, and Podman records this metadata so tools like podman inspect and podman run -P can use it. Option D is correct because EXPOSE serves primarily as documentation between the image creator and the container operator, indicating intended listening ports without actually opening or publishing them. Option B is wrong because EXPOSE has no relationship to environment variables; port configuration via env vars is a separate application-level concern.

Option C is wrong because EXPOSE does not create or enforce firewall rules in the container network namespace and does not block unexposed ports. Option E is wrong because EXPOSE alone does not publish ports to the host; publishing requires -p for explicit mapping or -P to publish all exposed ports to random host ports.

Exam trap

EX188 often tests the misconception that EXPOSE actually publishes or enforces ports; candidates confuse declarative metadata with runtime port publishing (-p/-P) and firewall enforcement.

36
Multi-Selecthard

You are writing a Containerfile for a Python web service. You want the image build to install dependencies and then run the service with predictable behavior across environments. Which TWO practices correctly apply build-time and runtime configuration in the Containerfile? (Choose two.)

Select 2 answers
A.Use ARG to declare a build-time variable such as APP_VERSION, then reference it in a RUN instruction to fetch the matching artifact.
B.Use ENV to set APP_VERSION and reference it in a RUN instruction to fetch the matching artifact.
C.Use ARG to set APP_PORT so the service can read it at runtime.
D.Use LABEL to set APP_PORT so the service can read it at runtime.
E.Use ENV to set a runtime variable such as APP_PORT so the service reads it when the container starts.
AnswersA, E

ARG declares variables that are available only during the build and can be referenced in instructions like RUN to influence what gets installed. This is appropriate for values such as a version or a package channel that affect the build result. The value is not persisted as a runtime environment variable, so it does not leak into the running container unless explicitly re-declared.

Why this answer

Build-time parameters that affect what is installed belong in ARG, while runtime configuration that the service reads on startup belongs in ENV. ARG keeps values out of the final runtime environment, and ENV makes defaults available to the process while still allowing overrides at podman run time. Using each instruction for its intended purpose yields predictable builds and predictable runtime behavior.

Exam trap

The trap here is treating ARG and ENV as interchangeable, when ARG is build-only and ENV persists into the running container.

37
MCQhard

How does Podman's rootless build architecture handle volume mounts or privileged operations specified within a RUN instruction in a Containerfile?

A.Rootless builds cannot execute RUN instructions that install RPM packages using dnf.
B.Rootless builds execute within user namespaces, mapping root inside the container to an unprivileged user on the host, restricting certain host-level operations.
C.Rootless builds automatically elevate privileges via sudo when a RUN instruction requires root access.
D.Rootless builds require the buildah daemon to be running as root in systemd.
AnswerB

Rootless builds run inside user namespaces, so root within the container maps to an unprivileged host UID. Privileged operations and host volume mounts are therefore constrained, since the build process lacks real host root privileges.

Why this answer

Podman rootless builds run inside a user namespace where the container's UID 0 is mapped to the invoking unprivileged user's UID on the host (via /etc/subuid and /etc/subgid ranges). This means RUN instructions that appear to run as root inside the build actually execute as an unprivileged user on the host, so operations requiring real host privileges — mounting block devices, changing host ownership outside the mapped range, or binding to privileged ports — are restricted or fail.

Exam trap

EX188 often tests the misconception that rootless builds cannot install packages or run privileged-looking commands at all, when in fact only host-level privileged operations are blocked — package installation inside the container filesystem works normally.

How to eliminate wrong answers

Option A is wrong because rootless builds can absolutely run dnf install inside a RUN instruction — package installation writes only to the container's own filesystem layer, which is permitted within the user namespace; the restriction is on host-level operations, not on package managers. Option C is wrong because Podman rootless builds never silently escalate via sudo; doing so would defeat the security model, and any elevation must be explicitly configured by the user outside the build. Option D is wrong because Podman is daemonless by design — there is no buildah daemon, and rootless builds do not require a root-owned systemd service; buildah runs as the invoking user.

38
Multi-Selecteasy

Which TWO instructions in a Containerfile can be used to set metadata or default execution parameters that influence how a container runs? (Choose two.)

Select 2 answers
A.RUN
B.CMD
C.ENTRYPOINT
D.COPY
E.FROM
AnswersB, C

CMD supplies the default command executed when a container starts, and it is overridden by arguments passed at runtime. This satisfies the stem's requirement for a default execution parameter, complementing ENTRYPOINT, which defines the fixed executable that CMD arguments feed into.

Why this answer

CMD [CORRECT] is right because it sets the default command (and/or default arguments) that the container executes when it starts if no command is supplied at runtime, directly influencing how the container runs. ENTRYPOINT [CORRECT] is also right because it configures the executable that the container always runs, defining the container's primary process and default execution behavior. Both are runtime metadata instructions stored in the image config, unlike build-time instructions.

RUN (A) executes commands during image build to create layers and does not set runtime defaults. COPY (D) only copies files from the build context into the image filesystem. FROM (E) merely specifies the base image for the build stage and has no role in runtime execution parameters.

Exam trap

EX188 often tests the build-time versus runtime distinction, tricking candidates into selecting RUN because it appears to 'do something' with commands, when only CMD and ENTRYPOINT affect how the container runs.

39
MCQeasy

When writing a Containerfile, which instruction specifies the base image to be used for the subsequent build steps?

A.BASE
B.INIT
C.FROM
D.PARENT
AnswerC

FROM declares the base image from which subsequent build steps run, and it must be the first instruction in a stage. It satisfies the stem because every later instruction, such as RUN or COPY, executes against the filesystem and metadata established by that base image.

Why this answer

Every Containerfile must start with a FROM instruction to define the base image.

40
MCQeasy

A developer wants to build a container image using podman build, but the Containerfile is named 'Customfile' and located in a subdirectory named 'dockerfiles'. Which command accomplishes this?

A.podman build -f dockerfiles/Customfile .
B.podman build --file-path dockerfiles/Customfile .
C.podman build -p dockerfiles/Customfile .
D.podman build --config dockerfiles/Customfile .
AnswerA

The -f flag overrides podman build's default Containerfile lookup, pointing it at dockerfiles/Customfile. The trailing dot supplies the build context, so podman reads instructions from that named file while resolving COPY and ADD paths relative to the current directory, satisfying both the non-standard filename and subdirectory location.

Why this answer

The `podman build` command uses the `-f` or `--file` flag to specify an alternative Containerfile. The correct syntax is `podman build -f dockerfiles/Customfile .`, where the path to the Containerfile is given relative to the current directory, and the build context is the current directory (`.`).

Exam trap

EX188 often tests the correct flag for specifying a Containerfile, and candidates may confuse `-f` with other flags like `--file-path` or `--config`.

How to eliminate wrong answers

Option B is wrong because `--file-path` is not a valid flag for `podman build`; the correct flag is `-f` or `--file`. Option C is wrong because `-p` is not a valid flag for specifying a Containerfile; it might be confused with `--pull` or other flags. Option D is wrong because `--config` is not a valid flag for specifying a Containerfile.

41
MCQhard

You are optimizing image build times and notice that a specific RUN instruction fetching dependencies is re-running on every build, even though the requirements.txt file has not changed. What is causing this behavior?

A.The COPY requirements.txt instruction was placed after an instruction that introduces non-deterministic data or the build context files have modified timestamps.
B.The Containerfile lacks an explicit CACHE instruction at the top.
C.Podman disables caching by default for all RUN instructions containing package managers.
D.The USER instruction was set to root, which disables layer caching.
AnswerA

Docker caches each layer keyed on the instruction and its inputs. If COPY requirements.txt sits after a layer whose content or timestamps change, that layer's cache invalidates, forcing the subsequent RUN to re-execute even though requirements.txt itself is unchanged.

Why this answer

Docker/Podman layer caching invalidates a RUN layer when any preceding instruction's layer changes. If COPY requirements.txt comes after an instruction that produces non-deterministic output (e.g., a RUN that fetches latest packages or writes timestamps) or if build-context files have changed mtimes, the cache key for the COPY layer changes, invalidating all subsequent RUN layers including the dependency install.

Exam trap

EX188 often tests the misconception that a special CACHE instruction or a flag controls caching, when the real cause is instruction ordering and build-context file changes invalidating the cache key.

How to eliminate wrong answers

Option B is wrong because there is no 'CACHE' instruction in Containerfile syntax — caching is automatic and controlled by instruction ordering and content hashes, not an explicit directive. Option C is wrong because Podman does not disable caching for package-manager RUN instructions; caching applies uniformly unless '--no-cache' is passed. Option D is wrong because the USER instruction has no effect on layer caching — cache keys are based on instruction content and parent layer digests, not the runtime user.

42
MCQmedium

An administrator needs to execute a package update and install dependencies during the podman build process, ensuring these commands are committed as a new layer in the final image. Which instruction accomplishes this?

A.EXEC
B.START
C.CMD
D.RUN
AnswerD

The RUN instruction executes shell commands during a build stage and commits the resulting filesystem changes as a new image layer. Package updates and dependency installs therefore persist in the final image, unlike CMD or ENTRYPOINT, which only define runtime behaviour.

Why this answer

`RUN` executes a command during the image build and commits the resulting filesystem changes as a new layer in the image. Using `RUN dnf update -y && dnf install -y <deps>` performs the package update and dependency install at build time, baking the results into the final image.

Exam trap

EX188 often tests build-time vs runtime instruction confusion — candidates pick `CMD` thinking it runs commands during build, when in fact only `RUN` executes at build time and commits a layer.

How to eliminate wrong answers

Option A is wrong because `EXEC` is not a Containerfile instruction — it resembles Kubernetes `exec` or a shell builtin but is not part of the Dockerfile/Containerfile grammar. Option B is wrong because `START` is not a valid Containerfile instruction; starting a process is a runtime concern handled by `CMD`/`ENTRYPOINT`, not a build directive. Option C is wrong because `CMD` sets the default command executed when a container starts from the image — it does not run at build time and does not create a layer.

43
MCQmedium

You want to build an image that has a build-time argument named 'VERSION'. How do you declare this variable inside the Containerfile so it can be used during the build steps?

A.DEFINE VERSION
B.ARG VERSION
C.ENV VERSION=1.0
D.VAR VERSION
AnswerB

ARG declares a build-time variable that exists only during image construction, so the VERSION value can be referenced by RUN instructions in the Containerfile. Unlike ENV, it is not persisted into the running container, satisfying the build-time-only constraint in the stem.

Why this answer

ARG is the Containerfile instruction that declares a build-time variable, which can be populated with --build-arg at build time and referenced in subsequent RUN, COPY, or other instructions. It exists only during the build and is not persisted in the final image's runtime environment, which is exactly the semantics required for a build-time VERSION variable.

Exam trap

EX188 often tests the distinction between ARG (build-time, not persisted) and ENV (runtime, persisted in the image), catching candidates who pick ENV because it 'also works' during the build.

How to eliminate wrong answers

Option A is wrong because DEFINE is not a valid Containerfile instruction — it is a C preprocessor directive and has no meaning in image builds. Option C is wrong because ENV sets a persistent environment variable that is baked into the image and visible at runtime; while it can be used during the build, it is not the correct choice for a build-time-only argument and cannot be overridden with --build-arg. Option D is wrong because VAR is not a Containerfile instruction in any OCI/Dockerfile specification.

44
MCQmedium

When writing a Containerfile, what is the difference between shell form and exec form for the CMD instruction?

A.There is no functional difference; they are syntactic aliases.
B.Exec form runs the executable directly without invoking a shell, making it receive Unix signals (like SIGTERM) properly as PID 1.
C.Shell form is required for multi-stage builds, while exec form is for single-stage builds.
D.Shell form runs the command as PID 1, while exec form spawns a bash shell wrapper.
AnswerB

Exec form passes the command as a JSON array, so the process runs directly as PID 1 without a shell wrapper. It therefore receives Unix signals such as SIGTERM itself, enabling graceful shutdown, whereas shell form spawns a shell that intercepts signals.

Why this answer

Exec form (JSON array syntax, e.g., CMD ["executable","arg1"]) runs the executable directly without a shell, so the process becomes PID 1 and receives Unix signals such as SIGTERM directly, enabling graceful shutdown. Shell form (CMD command arg1) wraps the command in /bin/sh -c, so the shell becomes PID 1 and may not forward signals to the child process. This distinction is critical for container lifecycle management.

Exam trap

EX188 often tests the misconception that shell form is 'more powerful' or that both forms behave identically, when the real differentiator is PID 1 signal handling and shell wrapping.

How to eliminate wrong answers

Option A is wrong because the two forms are not syntactic aliases; they differ in process invocation, signal handling, and variable expansion behavior. Option C is wrong because multi-stage builds are unrelated to CMD form; both forms work in any build stage, and multi-stage builds concern COPY --from and build stages, not CMD syntax. Option D is wrong because it reverses the behavior: shell form spawns a shell wrapper as PID 1, while exec form runs the executable directly as PID 1.

45
MCQmedium

A developer needs to optimize image size by removing build caches and temporary package manager cache files within the same RUN instruction. Why must this be done in a single RUN instruction?

A.Because file deletions in separate layers do not reduce the final image size due to the layered filesystem.
B.Because package managers lock the database across different layers.
C.Because the container build engine will fail if cache cleanup happens in a separate layer.
D.To ensure environment variables persist between installation and cleanup.
AnswerA

Each RUN instruction creates an immutable layer; deleting files in a later layer only adds a whiteout marker, leaving the original bytes in the earlier layer and thus in the final image. Combining download, install, cache removal and cleanup in one RUN prevents those bytes from ever being committed.

Why this answer

Container images are built as a stack of immutable layers, and each RUN instruction creates a new layer. If files are created in one RUN and deleted in a later RUN, the deletion only adds a whiteout marker in the new layer; the original files remain in the earlier layer and still contribute to the final image size. Performing installation and cleanup in a single RUN ensures the temporary files never persist in any committed layer.

Exam trap

EX188 often tests the misconception that deleting files in a later layer reduces image size, when in fact the layered filesystem preserves the original data unless creation and deletion occur in the same RUN instruction.

How to eliminate wrong answers

Option B is wrong because package managers do not lock their database across separate RUN layers in a way that prevents cleanup; the issue is purely layer immutability, not database locking. Option C is wrong because the build engine does not fail when cleanup is in a separate layer; it simply produces a larger image. Option D is wrong because environment variables set with ENV persist across layers regardless of RUN grouping, and persistence is not the reason for combining commands.

46
Multi-Selecthard

Which THREE practices are recommended when optimizing cache utilization during image builds with podman build?

Select 3 answers
A.Use the --no-cache flag on every routine build to ensure absolute freshness.
B.Always place COPY . . at the very top of the Containerfile before installing software dependencies.
C.Place instructions that change frequently, such as COPYing source code, near the end of the Containerfile.
D.Combine related package installation and cleanup steps into a single RUN instruction.
E.Order Containerfile instructions from least frequently changed to most frequently changed.
AnswersC, D, E

Frequently changing instructions such as COPY of source code invalidate the cache for that layer and every layer after it. Putting them last confines cache invalidation to the final steps, so earlier dependency layers remain reusable across rebuilds.

Why this answer

Option C is correct because placing frequently changing instructions such as COPYing source code near the end of the Containerfile preserves the cache for earlier, stable layers; when source changes, only the final layers are rebuilt. Option D is correct because combining related package installation and cleanup into a single RUN instruction creates one cacheable layer and avoids leaving package-manager metadata or temporary files in intermediate layers, which also reduces image size. Option E is correct because ordering instructions from least frequently changed to most frequently changed maximizes cache hits: stable base and dependency layers stay cached while only the volatile trailing layers are invalidated.

Option A is not recommended because --no-cache disables layer caching entirely, forcing full rebuilds and defeating cache optimization for routine builds. Option B is wrong because putting COPY . . at the top invalidates the cache for every subsequent instruction whenever any source file changes, so dependency installation and other expensive steps rerun unnecessarily.

Exam trap

EX188 often tests the misconception that --no-cache is a best practice for 'freshness' — in reality it destroys the layer cache and is only for troubleshooting or forced rebuilds.

47
MCQmedium

You need to ensure that a file copied into your image via the COPY instruction is owned by a specific user 'developer' and group 'devgroup'. How can this be achieved efficiently?

A.COPY app.py /app/app.py && chown developer:devgroup /app/app.py
B.COPY --chown=developer:devgroup app.py /app/app.py
C.COPY --user=developer:devgroup app.py /app/app.py
D.ADD --owner=developer app.py /app/app.py
AnswerB

COPY --chown sets ownership at copy time, so the file lands in the image layer already owned by developer:devgroup. This satisfies the stem's efficiency constraint by avoiding a separate RUN chown instruction, which would create an extra layer and duplicate the file's data.

Why this answer

The COPY instruction in a Containerfile supports the --chown flag, which sets the ownership of the copied files directly during the copy operation. This is the most efficient method because it avoids creating an extra layer and does not require the user/group to exist in the image beforehand. The syntax --chown=developer:devgroup correctly specifies both user and group.

Exam trap

EX188 often tests the difference between build-time instructions and runtime commands, and candidates may confuse --chown with --user or think that chown after COPY is equivalent, not realizing the layer and dependency implications.

How to eliminate wrong answers

Option A is wrong because it uses a shell command chown after COPY, which creates an additional layer and requires the user and group to already exist in the image. Option C is wrong because --user is not a valid flag for COPY; the correct flag is --chown. Option D is wrong because ADD does not support an --owner flag; ownership must be set with --chown, and ADD is generally discouraged for simple file copies.

48
MCQeasy

A team wants to document ownership and contact information directly in the image so that `podman inspect` shows who maintains it. Which Containerfile instruction should they add to set this metadata?

A.COMMENT maintainer="team@example.com"
B.ENV maintainer="team@example.com"
C.ARG maintainer="team@example.com"
D.LABEL maintainer="team@example.com"
AnswerD

LABEL adds arbitrary key-value metadata to the image, and maintainer is a commonly recognized key for contact information. The data becomes part of the image configuration and is visible through podman inspect, which is exactly the documentation goal described. Multiple LABEL instructions or a single instruction with several key=value pairs can be used.

Why this answer

Image metadata such as maintainer contact information is set with the LABEL instruction. Labels are stored in the image configuration and can be read with podman inspect, making them the correct mechanism for documenting ownership without affecting runtime behavior or build-time variables.

Exam trap

The trap here is assuming that any instruction which can hold a string value, such as ENV or ARG, is suitable for storing image metadata.

49
MCQmedium

A developer has written a Containerfile with multiple COPY instructions for static configuration files that change frequently, placed near the top of the Containerfile before the application code installation. Why is this considered a bad practice for build caching?

A.It invalidates the build cache for all subsequent instructions whenever those configuration files change, slowing down builds.
B.It violates OCI container image specification limits on COPY counts.
C.It causes the ENTRYPOINT instruction to fail at runtime.
D.It causes Podman to store duplicate layers in local storage, exhausting disk space.
AnswerA

Container image layers cache by instruction order, so a COPY of frequently changing configuration files near the top invalidates every subsequent layer, forcing application installation to rebuild each time. Moving volatile files later preserves caching for the expensive, stable application code layers.

Why this answer

Changing a file earlier in the Containerfile invalidates the cache for all subsequent instructions, forcing unnecessary rebuilds of heavy steps.

50
MCQhard

You need to copy local application source code from your build context into the /app directory inside the container image, automatically unpacking it if it is a local tar archive. Which instruction should you select?

A.FETCH
B.TRANSFER
C.COPY
D.ADD
AnswerD

ADD handles both local paths and remote URLs, and automatically extracts a local tar archive into the destination. COPY only copies files and never unpacks archives, so it cannot satisfy the automatic-unpacking constraint for the /app directory.

Why this answer

The ADD instruction in a Containerfile (Dockerfile) copies files from the build context into the image, and it has the additional feature of automatically unpacking local tar archives and fetching remote URLs. The COPY instruction only copies files and directories without unpacking or fetching. Therefore, ADD is the correct choice when you need to unpack a local tar archive into the image.

Exam trap

The trap is thinking that COPY can unpack archives, but it cannot; only ADD has that capability. Candidates might also confuse ADD with other instructions like FETCH or TRANSFER, which do not exist.

How to eliminate wrong answers

Option A is wrong because FETCH is not a valid Containerfile instruction. Option B is wrong because TRANSFER is not a valid Containerfile instruction. Option C is wrong because COPY does not unpack tar archives; it only copies files and directories as-is.

51
Multi-Selecteasy

Which TWO options are valid flags for the 'podman build' command to specify build arguments and tags? (Choose two.)

Select 2 answers
A.--volume
B.--publish
C.--build-arg
D.-t / --tag
E.--env-file
AnswersC, D

--build-arg passes a named variable into the build at run time, letting a Containerfile consume values such as versions or credentials without hard-coding them. It satisfies the stem's requirement for specifying build arguments, distinct from --tag, which names the resulting image.

Why this answer

Option C (--build-arg) is correct because 'podman build --build-arg KEY=VALUE' passes a build-time variable into the Containerfile/Dockerfile, matching the ARG instruction during the image build. Option D (-t / --tag) is correct because 'podman build -t name:tag' (or --tag) assigns a repository name and tag to the resulting image, which is exactly how you name built images. Option A (--volume) is not a build flag for specifying build arguments or tags; it is used with run/create to mount host paths into containers.

Option B (--publish) is also a run/create flag for mapping container ports to host ports, not a build argument or tag mechanism. Option E (--env-file) supplies environment variables at runtime for run/create, not build-time arguments or image tags, so it does not fit the scenario.

Exam trap

EX188 often tests confusion between 'podman build' flags and 'podman run' flags — options like --volume, --publish, and --env-file belong to run, not build.

52
MCQmedium

An auditor reviewing your Containerfile notices an EXPOSE instruction for port 80. What is the primary function of the EXPOSE instruction?

A.It documents which ports the container listens on at runtime.
B.It opens firewall ports on the underlying RHEL host system permanently.
C.It encrypts network traffic entering the specified container port.
D.It automatically publishes all exposed ports to random host ports without flags.
AnswerA

EXPOSE is metadata only; it records the port the image intends to listen on, informing users and tooling. It does not publish the port or alter runtime networking, which requires -p or -P at container start.

Why this answer

The EXPOSE instruction in a Containerfile is purely metadata — it documents the port the containerized application listens on, so tools like podman and image consumers know which port to publish. It does not actually open, publish, or firewall the port; the operator must still use -p or -P at runtime to map it to a host port.

Exam trap

EX188 often tests the misconception that EXPOSE actively opens or publishes a port, when it is only declarative metadata.

How to eliminate wrong answers

Option B is wrong because EXPOSE never touches the RHEL host firewall (firewalld/nftables); port publishing is handled by podman's port mapping at runtime, not by the image build. Option C is wrong because EXPOSE has nothing to do with encryption — TLS/SSL is configured in the application or a reverse proxy, not via EXPOSE. Option D is wrong because EXPOSE does not auto-publish ports; publishing requires the -P (capital) flag or explicit -p mappings, and even then it maps to random host ports only when -P is used.

53
MCQhard

A developer wants to pass a secret API key during the container build process without leaving the secret exposed in image layers or history. Which Podman feature should be used?

A.ARG API_KEY=secret_value
B.ENV API_KEY=secret_value
C.podman build --secret id=mysecret,src=/path/to/key.txt . with RUN --mount=type=secret,id=mysecret ...
D.ADD /path/to/key.txt /app/key.txt followed by RUN rm /app/key.txt
AnswerC

Build secrets mount the key only during the RUN instruction via a temporary filesystem, so it never persists in image layers or history. This satisfies the requirement to pass the API key without exposing it in the resulting image.

Why this answer

Podman supports build-time secrets using the --secret flag and the --mount=type=secret directive in the Containerfile.

Ready to test yourself?

Try a timed practice session using only Container Image Building questions.