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?
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 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.
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.
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/
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ayuuk
Highly Voted 4 years, 8 months agofredurst
4 years, 4 months agoSCI_FI
Most Recent 7 months, 4 weeks ago[Removed]
2 years, 6 months ago[Removed]
3 years agogilbertlelancelo
3 years, 1 month agoBlob21
3 years, 2 months agohmagroun
4 years, 5 months agohector1978
4 years, 7 months ago