nerdexam
Linux_Foundation

KCNA · Question #68

What is a best practice to minimize the container image size?

The correct answer is B. Use multistage builds. Using multistage builds is a best practice for minimizing container image size by separating build-time dependencies from runtime dependencies.

Submitted by carlos_mx· May 4, 2026Cloud Native Application Delivery

Question

What is a best practice to minimize the container image size?

Options

  • AUse a DockerFile.
  • BUse multistage builds.
  • CBuild images with different tags.
  • DAdd a build.sh script.

How the community answered

(38 responses)
  • A
    5% (2)
  • B
    89% (34)
  • C
    3% (1)
  • D
    3% (1)

Why each option

Using multistage builds is a best practice for minimizing container image size by separating build-time dependencies from runtime dependencies.

AUse a DockerFile.

While a Dockerfile is essential for building images, merely using one does not inherently guarantee a small image size; the instructions within it determine the size.

BUse multistage builds.Correct

Multistage builds allow you to use multiple `FROM` statements in your Dockerfile, where each `FROM` instruction can use a different base image, and critically, you can copy only the necessary artifacts from one stage to a leaner final stage, thereby discarding all build tools and intermediate layers that are not needed at runtime.

CBuild images with different tags.

Building images with different tags helps with versioning and management, but it does not directly minimize the size of any individual image.

DAdd a build.sh script.

Adding a `build.sh` script external to the Dockerfile simply automates the build process but does not, by itself, reduce the final image size.

Concept tested: Docker image size optimization

Source: https://docs.docker.com/build/building/multi-stage/

Topics

#Container Images#Image Optimization#Multistage Builds#Docker Best Practices

Community Discussion

No community discussion yet for this question.

Full KCNA Practice