Docker RUN vs CMD vs ENTRYPOINT

<p>In Docker build, the three instructions&nbsp;<code>RUN</code>&nbsp;,&nbsp;<code>CMD</code>&nbsp;and&nbsp;<code>ENTRYPOINT</code>&nbsp;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&rsquo;s discuss their differences in this article.</p> <h1>RUN vs CMD vs ENTRYPOINT</h1> <ul> <li><code>RUN</code>&nbsp;executes commands and creates new image layers.</li> <li><code>CMD</code>&nbsp;sets the command and its parameters to be executed by default after the container is started. However&nbsp;<code>CMD</code>&nbsp;can be replaced by&nbsp;<code>docker run</code>&nbsp;command line parameters.</li> <li><code>ENTRYPOINT</code>&nbsp;configures the command to run when the container starts, similar to&nbsp;<code>CMD</code>&nbsp;from a functionality perspective.</li> </ul> <h1>Shell Format vs Exec Format</h1> <p>We can specify the command to be run by RUN, CMD and ENTRYPOINT in two ways:&nbsp;<code>Shell format</code>&nbsp;and&nbsp;<code>Exec format</code>, which have subtle differences in usage.</p> <h2>Shell Format</h2> <p>Shell format has the following form:</p> <p><a href="https://tonylixu.medium.com/docker-run-vs-cmd-vs-entrypoint-57f248b95889"><strong>Visit Now</strong></a></p>
Tags: Docker Run