ENTRYPOINT vs CMD difference in Docker - Performance Comparison
We want to understand how Docker handles commands when using ENTRYPOINT and CMD.
How does Docker decide which command to run and how does this affect execution?
Analyze the time complexity of the following Dockerfile snippet.
FROM alpine
ENTRYPOINT ["echo"]
CMD ["Hello, World!"]
This Dockerfile sets ENTRYPOINT to "echo" and CMD to a default message.
Look for repeated or dominant operations in command execution.
- Primary operation: Docker runs the ENTRYPOINT command once per container start.
- How many times: Exactly once each time the container runs.
The command runs once regardless of input size.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 1 |
| 100 | 1 |
| 1000 | 1 |
Pattern observation: The number of operations stays the same no matter the input size.
Time Complexity: O(1)
This means the command runs once per container start, no matter how big the input is.
[X] Wrong: "ENTRYPOINT and CMD run multiple times or loop over inputs."
[OK] Correct: Both run only once when the container starts; they do not repeat or loop automatically.
Knowing how ENTRYPOINT and CMD work helps you explain container startup behavior clearly and confidently.
"What if we replaced ENTRYPOINT with CMD only? How would the command execution change?"