0
0
Dockerdevops~20 mins

ENTRYPOINT vs CMD difference in Docker - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ENTRYPOINT vs CMD Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Difference between ENTRYPOINT and CMD in Docker

Which statement best describes the difference between ENTRYPOINT and CMD in a Dockerfile?

A<code>CMD</code> sets the main command that always runs, while <code>ENTRYPOINT</code> provides default arguments that can be overridden at runtime.
B<code>ENTRYPOINT</code> sets the main command that always runs, while <code>CMD</code> provides default arguments that can be overridden at runtime.
C<code>ENTRYPOINT</code> and <code>CMD</code> are interchangeable and have no difference in behavior.
D<code>CMD</code> is used only for environment variables, while <code>ENTRYPOINT</code> runs the main command.
Attempts:
2 left
💡 Hint

Think about which instruction defines the fixed command and which one sets default parameters.

💻 Command Output
intermediate
1:30remaining
Output of Docker container with ENTRYPOINT and CMD

Given this Dockerfile snippet, what will be the output when running docker run myimage?

ENTRYPOINT ["echo"]
CMD ["Hello World"]
ANo output, container exits immediately
Becho Hello World
CHello World
DError: invalid command
Attempts:
2 left
💡 Hint

Remember how ENTRYPOINT and CMD combine when both are arrays.

🔀 Workflow
advanced
2:00remaining
Combining ENTRYPOINT and CMD for flexible container commands

You want a Docker container that always runs python3 but allows users to pass different scripts or arguments when running the container. Which Dockerfile setup achieves this?

A
ENTRYPOINT ["python3"]
CMD ["script.py"]
BCMD ["python3", "script.py"]
C
ENTRYPOINT ["script.py"]
CMD ["python3"]
D
CMD ["script.py"]
ENTRYPOINT ["python3"]
Attempts:
2 left
💡 Hint

Think about which instruction fixes the executable and which provides default arguments.

Troubleshoot
advanced
2:00remaining
Why does overriding CMD not change the command when ENTRYPOINT is set?

You have this Dockerfile:

ENTRYPOINT ["/bin/bash"]
CMD ["-c", "echo Hello"]

Running docker run myimage ls does not list files but opens a bash shell. Why?

ABecause the Dockerfile syntax is invalid and causes fallback to default shell.
BBecause <code>CMD</code> always overrides <code>ENTRYPOINT</code> and <code>ls</code> is ignored.
CBecause <code>docker run</code> ignores command line arguments when ENTRYPOINT is set.
DBecause <code>ENTRYPOINT</code> is fixed to <code>/bin/bash</code> and <code>ls</code> is passed as argument, overriding CMD but not changing ENTRYPOINT.
Attempts:
2 left
💡 Hint

Consider how command line arguments interact with ENTRYPOINT and CMD.

Best Practice
expert
2:30remaining
Best practice for making a Docker container behave like a command-line tool

You are creating a Docker image for a CLI tool. You want users to run commands like docker run tool image.jpg and have tool process image.jpg. Which Dockerfile setup is best?

AUse <code>ENTRYPOINT</code> to set the tool executable and <code>CMD</code> to provide default arguments or none.
BUse only <code>CMD</code> to set the tool executable and arguments.
CDo not use <code>ENTRYPOINT</code> or <code>CMD</code>; require users to specify full command.
DUse <code>ENTRYPOINT</code> to set default arguments and <code>CMD</code> to set the executable.
Attempts:
2 left
💡 Hint

Think about fixing the executable and allowing flexible arguments.