0
0
Dockerdevops~10 mins

ENTRYPOINT vs CMD difference in Docker - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Process Flow - ENTRYPOINT vs CMD difference
Dockerfile Build
Set ENTRYPOINT?
NoDefault ENTRYPOINT: none
|Yes
Set CMD?
NoDefault CMD: none
|Yes
Container Run
Run ENTRYPOINT + CMD
Override CMD with args?
YesRun ENTRYPOINT + new args
No
Container runs with ENTRYPOINT + CMD
Docker builds image setting ENTRYPOINT and CMD. When running container, ENTRYPOINT runs always, CMD provides default arguments. CMD can be overridden at run time.
Execution Sample
Docker
FROM alpine
ENTRYPOINT ["echo"]
CMD ["Hello, World!"]
This Dockerfile sets ENTRYPOINT to 'echo' and CMD to 'Hello, World!'. Running container prints 'Hello, World!'.
Process Table
StepActionENTRYPOINTCMDRun CommandOutput
1Build imageechoHello, World!N/AN/A
2Run container without argsechoHello, World!echo Hello, World!Hello, World!
3Run container with args 'Hi there'echoHello, World!echo Hi thereHi there
4Run container overriding ENTRYPOINT (not typical)/bin/echoHello, World!/bin/echo Hello, World!Hello, World!
5Run container with no ENTRYPOINT or CMDnonenonenoneNo command runs
💡 Container stops after running the combined ENTRYPOINT and CMD or overridden command.
Status Tracker
VariableStartAfter BuildAfter Run No ArgsAfter Run With ArgsAfter ENTRYPOINT Override
ENTRYPOINTnoneechoechoecho/bin/echo
CMDnoneHello, World!Hello, World!Hi thereHello, World!
Run CommandnoneN/Aecho Hello, World!echo Hi there/bin/echo Hello, World!
Key Moments - 3 Insights
Why does the container run 'echo Hello, World!' when no arguments are given?
Because ENTRYPOINT is set to 'echo' and CMD provides default arguments 'Hello, World!'. See execution_table row 2.
What happens if you provide arguments when running the container?
The CMD default arguments are replaced by the new arguments, but ENTRYPOINT stays the same. See execution_table row 3.
Can ENTRYPOINT be overridden at runtime like CMD?
Yes, but it is less common and requires special syntax. Overriding ENTRYPOINT changes the main command run. See execution_table row 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the run command at step 3?
Aecho Hi there
B/bin/sh Hello, World!
Cecho Hello, World!
Dnone
💡 Hint
Check the 'Run Command' column at step 3 in the execution_table.
At which step does the ENTRYPOINT get overridden?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Look at the 'ENTRYPOINT' column changes in variable_tracker and execution_table.
If CMD is not set, but ENTRYPOINT is 'echo', what happens when you run the container with no arguments?
AContainer runs default shell
BContainer fails to run
CContainer runs 'echo' with no arguments and prints nothing
DContainer runs 'echo Hello, World!'
💡 Hint
Think about how ENTRYPOINT and CMD combine; CMD provides default args if present.
Concept Snapshot
ENTRYPOINT sets the main command always run.
CMD provides default arguments to ENTRYPOINT.
CMD can be overridden at container run.
ENTRYPOINT can be overridden but less common.
Without ENTRYPOINT, CMD runs as command.
Together they define container start behavior.
Full Transcript
Docker images can define ENTRYPOINT and CMD. ENTRYPOINT is the main command that always runs when the container starts. CMD provides default arguments to ENTRYPOINT or acts as the command if ENTRYPOINT is not set. When running a container, you can override CMD by passing new arguments, but ENTRYPOINT stays unless explicitly overridden. This lets you set a fixed command with flexible arguments. The execution table shows how ENTRYPOINT and CMD combine to form the final run command and output. Overriding ENTRYPOINT changes the main command, which is less common. Understanding this helps control container startup behavior clearly.