Recall & Review
beginner
What is the purpose of the CMD instruction in a Dockerfile?
CMD sets the default command that runs when a container starts from the image.
Click to reveal answer
beginner
How many CMD instructions can a Dockerfile have?
Only one CMD instruction is allowed; if multiple are present, the last one takes effect.
Click to reveal answer
intermediate
What happens if you run a Docker container and provide a command after the image name?
The provided command overrides the CMD instruction in the Dockerfile for that container run.
Click to reveal answer
beginner
Show the syntax of CMD using exec form in a Dockerfile.
CMD ["executable", "param1", "param2"] - This form runs the command directly without a shell.
Click to reveal answer
intermediate
What is the difference between CMD and ENTRYPOINT in Docker?
CMD provides default arguments for ENTRYPOINT or a default command, while ENTRYPOINT sets a fixed command that always runs.
Click to reveal answer
What does the CMD instruction do in a Dockerfile?
✗ Incorrect
CMD sets the default command that runs when the container starts.
If a Dockerfile has multiple CMD instructions, which one is used?
✗ Incorrect
Only the last CMD instruction in the Dockerfile is used.
How can you override the CMD command when running a container?
✗ Incorrect
Providing a command after the image name in 'docker run' overrides CMD.
Which CMD syntax runs the command without a shell?
✗ Incorrect
The exec form uses JSON array syntax and runs the command directly.
What is the main difference between CMD and ENTRYPOINT?
✗ Incorrect
CMD provides default command or arguments; ENTRYPOINT sets the command that always runs.
Explain how the CMD instruction works in a Dockerfile and how it interacts with commands given at container run time.
Think about what happens if you run a container with or without extra commands.
You got /3 concepts.
Describe the difference between the exec form and shell form of the CMD instruction.
Consider how the command is executed inside the container.
You got /4 concepts.