0
0
Dockerdevops~5 mins

CMD instruction for default command in Docker - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ASets the default command to run in the container
BBuilds the Docker image
CCopies files into the image
DDefines environment variables
If a Dockerfile has multiple CMD instructions, which one is used?
AThe last CMD instruction
BThe first CMD instruction
CAll CMD instructions run in order
DNone, it causes an error
How can you override the CMD command when running a container?
ABy changing the ENTRYPOINT
BBy specifying a command after the image name in 'docker run'
CBy editing the Dockerfile after building
DBy using the ENV instruction
Which CMD syntax runs the command without a shell?
ACMD executable param1 param2
BCMD (executable param1 param2)
CCMD "executable param1 param2"
DCMD ["executable", "param1", "param2"]
What is the main difference between CMD and ENTRYPOINT?
ACMD copies files; ENTRYPOINT runs commands
BCMD builds image; ENTRYPOINT runs container
CCMD sets default command; ENTRYPOINT sets fixed command
DCMD sets environment; ENTRYPOINT sets volumes
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.