<p>I want to know whether it’s possible to make a <code>FROM</code> instruction in a Dockerfile pull the most recent image (e.g. <code>image:latest</code>) before proceeding with the build?</p>

<p>Currently, the image is only pulled if it’s not already stored locally.</p>

<p><code>docker build --pull OTHER_OPTIONS PATH</code></p>

<p>From <a href="https://docs.docker.com/engine/reference/commandline/build/" rel="nofollow noreferrer">https://docs.docker.com/engine/reference/commandline/build/</a></p>

<pre><code>--pull      Always attempt to pull a newer version of the image
</code></pre>

<p>Although there might be genuine use case for this for development pupose, I strongly suggest avoid depending on this option in production builds. Docker images must be immutable. Using this option can lead to situations where different images are generated from same source code and any behaviour changes resulting from such builds without corresponding changes in code are hard to debug. </p>

<p>Say there is a project called "derived project" which uses the base image <code>myBaseImage:latest</code></p>

<pre><code>FROM myBaseImage:latest

&lt;snipped&gt;

CMD xyz
</code></pre>

<pre><code>docker build --pull -t myDerivedImage:&lt;version of source code&gt; .
</code></pre>

<p>Assuming the tag of derived image is based on it's source code version (a git commit hash for example) which is the most common way to tag the images, if a new base image under latest tag is published while there are no changes in derived project, the build of derived project will produce different images under same name before and after the base image change. Once an image is published under a name, it should not be mutated. </p>
