In Docker build, the three instructions RUN , CMD and ENTRYPOINT look similar and all are instructions used in a Dockerfile to define various aspects of a Docker image. Sometimes it can easily cause confusions. Let’s discuss their differences in this article.
RUN vs CMD vs ENTRYPOINT
RUNexecutes commands and creates new image layers.CMDsets the command and its parameters to be executed by default after the container is started. HoweverCMDcan be replaced bydocker runcommand line parameters.ENTRYPOINTconfigures the command to run when the container starts, similar toCMDfrom a functionality perspective.
Shell Format vs Exec Format
We can specify the command to be run by RUN, CMD and ENTRYPOINT in two ways: Shell format and Exec format, which have subtle differences in usage.
Shell Format
Shell format has the following form: