CKAD Application Design and Build Practice Question
You have a Dockerfile with 'CMD ["nginx", "-g", "daemon off;"]'. A developer wants to run the container with a different command: 'nginx -t'. How should they run the container?
⚠ Common exam trap
Many exam-takers confuse the Docker CLI syntax with Dockerfile instructions, thinking they need to include 'CMD' or use JSON array syntax on the command line, when in reality the command is simply appended as a string after the image name.
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
✓
docker run nginx nginx -t
`docker run nginx nginx -t` passes `nginx -t` as the command to override the Dockerfile's `CMD`. The CMD instruction in the Dockerfile is replaced entirely by the command-line arguments after the image name, so the container runs `nginx -t` instead of `nginx -g 'daemon off;'`. This is the standard Docker behavior for overriding the default command.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
docker run nginx ["nginx", "-t"]
Why it's wrong here
The docker run CLI interprets the trailing arguments as a command and its arguments, but it does not accept JSON array syntax. Writing ["nginx", "-t"] causes the shell to treat the brackets as a glob or literal command name, resulting in an error like 'exec: \"[nginx\": executable file not found'. To override CMD, you pass plain space-separated words after the image name, not exec-form JSON.
- ✗
docker run nginx CMD nginx -t
Why it's wrong here
The keyword CMD is a Dockerfile instruction, not a docker run parameter. When you append CMD nginx -t to the image name, Docker treats the literal string 'CMD' as the first argument of the command to execute, so it attempts to run a binary named 'CMD' inside the container, which does not exist. To override the image's CMD, simply place the desired command and arguments directly after the image name, without any keyword prefix.
- ✓
docker run nginx nginx -t
Why this is correct
This is the correct syntax because anything after the image name in docker run becomes the command that overrides the Dockerfile's CMD instruction. The image's CMD is nginx -g daemon off, but here nginx -t replaces it entirely, causing the container to run nginx's configuration test and exit with a status indicating success or failure. This runtime override is the standard mechanism for changing the default command of a container.
- ✗
docker run --entrypoint nginx -t nginx
Why it's wrong here
The --entrypoint flag overrides the ENTRYPOINT, not the CMD, which changes how the command is assembled. Here it sets the entrypoint to nginx and then passes '-t nginx' as arguments, resulting in nginx -t nginx, which is invalid because nginx -t expects no additional non-option arguments. Additionally, the placement of the flag and the ambiguous arguments make it impossible to achieve the intended CMD override; the correct approach is to use trailing arguments after the image name.
Go deeper
Related to this question
About these practice questions
Courseiva writes every CKAD question from scratch — 826 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.