0
0
Dockerdevops~20 mins

CMD instruction for default command in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CMD Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Dockerfile CMD instruction?
Given the Dockerfile snippet below, what will be the output when running the container without any additional command?
Docker
FROM alpine
CMD ["echo", "Hello World"]
Aecho Hello World
BNo output, container exits immediately
CHello World
DError: CMD syntax invalid
Attempts:
2 left
💡 Hint
CMD defines the default command and arguments for the container.
🧠 Conceptual
intermediate
2:00remaining
What happens if you specify CMD multiple times in a Dockerfile?
Consider a Dockerfile with multiple CMD instructions. Which statement is true about how Docker handles them?
AOnly the last CMD instruction is used as the default command.
BAll CMD instructions run sequentially when the container starts.
CDocker throws an error during build for multiple CMD instructions.
DThe first CMD instruction is used and others are ignored.
Attempts:
2 left
💡 Hint
Think about how Docker layers and instructions override each other.
🔀 Workflow
advanced
2:00remaining
How to override the CMD default command when running a container?
You have a Docker image with CMD ["python", "app.py"]. How can you run the container to execute 'python test.py' instead?
Adocker run image_name -c python test.py
Bdocker run image_name python test.py
Cdocker run image_name CMD python test.py
Ddocker run image_name --cmd python test.py
Attempts:
2 left
💡 Hint
The CMD can be overridden by specifying a command after the image name.
Troubleshoot
advanced
2:00remaining
Why does this Docker container exit immediately after starting?
Dockerfile: FROM ubuntu CMD ["python"] You run the container but it exits immediately. What is the most likely cause?
AThe python command is not installed in the image.
BThe container has no foreground process and exits immediately.
CThe CMD syntax is incorrect and causes an error.
DDocker daemon is not running.
Attempts:
2 left
💡 Hint
Check if the command in CMD exists inside the container.
Best Practice
expert
2:00remaining
What is the recommended form of CMD instruction for best compatibility?
Which CMD instruction form is best practice to avoid shell processing issues and signal handling problems?
ACMD echo "Hello World"
BCMD echo Hello World
CCMD /bin/sh -c "echo Hello World"
DCMD ["echo", "Hello World"]
Attempts:
2 left
💡 Hint
Consider how Docker executes commands and handles signals.