Dockerfile: CMD vs ENTRYPOINT
Source: Dev.to
Default CMD in the Ubuntu Image
The official Ubuntu image defines a default command:
CMD ["/bin/bash"]
When you run a container and provide arguments, those arguments replace the default CMD.
docker run --rm --name cmd ubuntu:latest ls /home
docker run --rm --name cmd ubuntu:latest date
Example outputs
# List contents of /home/ubuntu
docker run --rm --name cmd ubuntu:latest ls -l /home/ubuntu
total 0
# Show the current date
docker run --rm --name cmd ubuntu:latest date
Sat Dec 13 16:22:53 UTC 2025
Creating an Image with ENTRYPOINT
Below is a simple Dockerfile that sets an ENTRYPOINT script and provides a default argument via CMD.
FROM ubuntu:latest
WORKDIR /app
COPY script.sh .
RUN ["chmod", "+x", "script.sh"]
ENTRYPOINT ["/app/script.sh"]
CMD ["world"]
script.sh
#!/bin/bash
echo "Hello $1"
The script expects a single argument. If no argument is supplied at runtime, the value from CMD (world) is used.
Running the Image
Using the default argument
docker run --rm --name entrypoint entrypoint:1.0.0
# Output:
# Hello world
Overriding the argument
docker run --rm --name entrypoint entrypoint:1.0.0 december
# Output:
# Hello december
Key Takeaways
- The
CMDinstruction can always be overridden by providing arguments when running a container. - The
ENTRYPOINTitself cannot be overridden at runtime, but you can change the arguments passed to it by specifying a differentCMD(or by providing arguments directly indocker run). - Choose between
ENTRYPOINTandCMDbased on the intended use case: useENTRYPOINTfor a fixed executable andCMDfor default arguments or an alternative command.