Complete referenece of dockerfile cmd and entrypoint

What is the benefit of using CMD?

CMD instruction can be used to set default command to execute when we run docker container. It allows the user to execute some particular command while running docker container.

Docker file has CMD echo "This is test"
docker run -it 7de4bed89922 
This is test

docker run -it 7de4bed89922 /bin/bash
root@7de4bed89922:/#

What is the benefit of using ENTRYPOINT?

ENTRYPOINT instruction allows you to configure a container that will run as an executable. It has two forms – exec and shell

Exec form allows to set commands and parameters and then use either form of CMD to set additional parameters that are more likely to be changed. Where as shell form ignores any CMD or docker run command line arguments

Difference between CMD and ENTRYPOINT

CMDENTRYPOINT
CMD commands can be overwritten during docker runENTRYPOINT commands cannot be overwritten
Parameters passed are replaced Parameters passed is appended