Challenge - 5 Problems
CMD Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2: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"]
Attempts:
2 left
💡 Hint
CMD defines the default command and arguments for the container.
✗ Incorrect
The CMD instruction specifies the default command to run when the container starts. Here, it runs 'echo Hello World', so the output is 'Hello World'.
🧠 Conceptual
intermediate2: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?
Attempts:
2 left
💡 Hint
Think about how Docker layers and instructions override each other.
✗ Incorrect
Docker uses only the last CMD instruction in the Dockerfile as the default command for the container.
🔀 Workflow
advanced2: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?
Attempts:
2 left
💡 Hint
The CMD can be overridden by specifying a command after the image name.
✗ Incorrect
When running a container, any command after the image name overrides the CMD default command.
❓ Troubleshoot
advanced2: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?
Attempts:
2 left
💡 Hint
Check if the command in CMD exists inside the container.
✗ Incorrect
Ubuntu base image does not have 'python' installed by default, so the command fails and container exits immediately.
✅ Best Practice
expert2: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?
Attempts:
2 left
💡 Hint
Consider how Docker executes commands and handles signals.
✗ Incorrect
The exec form (JSON array) of CMD avoids shell wrapping, improving signal handling and avoiding shell parsing issues.