CKAD Application Design and Build Practice Question
Which of the following is true about the CMD instruction in a Dockerfile?
⚠ Common exam trap
Many candidates confuse CMD with RUN, thinking CMD runs during build, or mistakenly believe CMD and ENTRYPOINT are mutually exclusive, when in fact they are designed to work together.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
CMD provides a default command that can be overridden at runtime
The CMD instruction in a Dockerfile provides default arguments for the container's main process, which can be overridden when the container is started with a command-line argument (e.g., `docker run <image> <command>`). It is not executed during the image build (that's RUN), it does not expose ports (that's EXPOSE), and it can be used with ENTRYPOINT to supply default parameters that are overridable.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
CMD is always executed during the image build process
Why it's wrong here
This is false because CMD is a runtime instruction, not a build step. During a docker build, only RUN instructions execute commands to create layers; CMD merely sets the default command that runs when the container starts. If you run a build, you won't see the CMD output at build time. Also note that CMD doesn't affect the image layers beyond metadata.
- ✗
CMD is used to expose ports
Why it's wrong here
This is incorrect; port exposure is handled by the EXPOSE instruction in the Dockerfile. CMD defines the executable/arguments for the container's default behavior, not network configuration. EXPOSE documents which ports the container listens on; CMD has nothing to do with networking.
- ✗
CMD cannot be used in conjunction with ENTRYPOINT
Why it's wrong here
This is false; CMD and ENTRYPOINT complement each other. When both are specified, ENTRYPOINT gives the main executable and CMD supplies default arguments to that entrypoint. At runtime you can override these arguments. They are often used together, e.g., ENTRYPOINT ["echo"] CMD ["hello"].
- ✓
CMD provides a default command that can be overridden at runtime
Why this is correct
This is correct. CMD defines the default command and parameters that run when the container starts, but it is intentionally overridable. For example, docker run image <command> replaces the CMD entirely. This flexibility makes CMD useful for providing sensible defaults while allowing users to supply their own command.
Go deeper
Related to this question
About these practice questions
This CKAD question is part of Courseiva's 826-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This CKAD practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CKAD exam.