DCA · Question #160
DCA Question #160: Real Exam Question with Answer & Explanation
The correct answer is A: at the bottom of the Dockerfile. To leverage Docker build caching effectively and speed up builds, the most frequently changed parts of a Docker image should be placed at the bottom of the Dockerfile.
Question
Some Docker images take time to build through a Continuous Integration environment. You want to speed up builds and take advantage of build caching. Where should the most frequently changed part of a Docker image be placed in a Dockerfile?
Options
- Aat the bottom of the Dockerfile
- Bafter the FROM directive
- Cat the top of the Dockerfile
- Din the ENTRYPOINT directive
Explanation
To leverage Docker build caching effectively and speed up builds, the most frequently changed parts of a Docker image should be placed at the bottom of the Dockerfile.
Common mistakes.
- B. Placing frequently changed parts directly after
FROMwould cause almost the entire build cache to be invalidated and rebuilt on most changes, significantly hindering caching benefits. - C. Placing frequently changed parts at the top would similarly invalidate the cache for all subsequent layers in the Dockerfile, leading to minimal caching efficiency.
- D. The
ENTRYPOINTdirective defines the command executed when the container starts and, while typically towards the bottom, it's not the primary strategy for placing frequently changed content for build caching.
Concept tested. Dockerfile build caching optimization
Reference. https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#leverage-build-cache
Topics
Community Discussion
No community discussion yet for this question.