Both CMD and ENTRYPOINT in a Dockerfile are used to specify the command to execute when the container starts, but they behave differently. CMD can be overridden by command-line arguments in docker run, while ENTRYPOINT cannot be overridden, and docker run arguments are passed as parameters to ENTRYPOINT. CMD has three forms: CMD ["executable","param1","param2"] (exec form), CMD command param1 param2 (shell form), CMD ["param1","param2"] (as parameters to ENTRYPOINT). ENTRYPOINT also has exec and shell forms. Best practice is to use ENTRYPOINT to define the executable and CMD to define default parameters.