701-100 Exam QuestionsBrowse all questions from this exam

701-100 Exam - Question 28


Given the following excerpt of a Dockerfile:

Run apt-get ""y update && apt-get install ""y fortunes && apt-get clean

Why are the multiple apt-get commands combined in one RUN statement instead of using multiple RUN statements?

Show Answer
Correct Answer: CD

Combining multiple apt-get commands in a single RUN statement helps to avoid the creation of unnecessary images. Docker creates a new image layer for each RUN statement. By combining commands, all actions are executed in one layer, which minimizes the number of layers and helps keep the Docker image smaller and more efficient.

Discussion

8 comments
Sign in to comment
ayuukOption: C
Dec 21, 2019

Correct is C. Minimize the number of layers In older versions of Docker, it was important that you minimized the number of layers in your images to ensure they were performant. The following features were added to reduce this limitation: Only the instructions RUN, COPY, ADD create layers. Other instructions create temporary intermediate images, and do not increase the size of the build. Where possible, use multi-stage builds, and only copy the artifacts you need into the final image. This allows you to include tools and debug information in your intermediate build stages without increasing the size of the final image.

fredurst
May 4, 2020

hello,can i find another practice exam

hmagrounOption: C
Mar 23, 2020

"C" is the correct answer

Blob21Option: C
Jun 23, 2021

https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

gilbertlelanceloOption: D
Aug 2, 2021

Ans D. Using RUN apt-get update && apt-get install -y ensures your Dockerfile installs the latest package versions with no further coding or manual intervention. This technique is known as “cache busting”. You can also achieve cache-busting by specifying a package version. This is known as version pinning, https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

hector1978Option: C
Feb 17, 2020

I agree, the correct answer is C

[Removed]Option: C
Aug 25, 2021

From: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#minimize-the-number-of-layers Only the instructions RUN, COPY, ADD create layers. Other instructions create temporary intermediate images, and do not increase the size of the build.

[Removed]Option: C
Mar 1, 2022

Correct is C

SCI_FIOption: D
Jan 19, 2024

I think is D.