DevOps Tools Engineer (LPIC-OT 701) — Question 6
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?
Answer options
- A. To prevent the commands from running in parallel because Docker executes all RUN statements in their own container at the same time.
- B. To ensure the execution order of the commands because Docker might evaluate the statements of a Dockerfile in any order.
- C. To avoid the creation of unnecessary images because Docker creates a new image for each RUN statement.
- D. To execute both commands in the same container instance and void Docker to reset the container to the original base image.
- E. To execute the apt-get install command only if the apt-get update command was successful because Docker does not check the success of RUN statements.
Correct answer: D
Explanation
The correct answer is D because combining the commands in a single RUN instruction allows them to execute in the same container instance, thus preventing Docker from reverting to the original base image after each RUN. The other options are incorrect as they misinterpret how Docker handles command execution, parallelism, and image creation.