<p>I have an application that I am converting into a docker container.</p>

<p>I am going to test some different configuration for the application regarding persisted vs non persisted storage.</p>

<p>E.g. in one scenario I am going to create a persisted volume and mount some data into that volume.</p>

<p>In another scenario I am going to test <em>not</em> having any persisted volume (and accept that any date generated while the container is running is gone when its stopped/restarted).</p>

<p>Regarding the first scenario that works fine. But when I am testing the second scenario - no persisted storage - I am not quite sure what to do on the docker side.</p>

<p>Basically does it make any sense do define a volume in my Dockerfile when I don't plan to have any persisted volumes in kubernetes?</p>

<p>E.g. here is the end of my <code>Dockerfile</code></p>

<pre><code>...
ENTRYPOINT ["./bin/run.sh"]
VOLUME /opt/application-x/data
</code></pre>

<p>So does it make any sense at all to have the last line when I don't create and kubernetes volumes? </p>

<p>Or to put it in another way, are there scenarios where creating a volume in a dockerfile makes sense even though no corresponding persistent volumes are created?</p>

u123
<p>It usually doesn’t make sense to define a VOLUME in your Dockerfile.</p>

<p>You can use the <code>docker run -v</code> option or Kubernetes’s container volume mount setting on any directory in the container filesystem space, regardless of whether or not its image originally declared it as a VOLUME.  Conversely, a VOLUME can leak anonymous volumes in an iterative development sequence, and breaks RUN commands later in the Dockerfile.</p>

<p>In the scenario you describe, if you don’t have a VOLUME, everything is straightforward: if you mount something on to that path, in either plain Docker or Kubernetes, storage uses the mounted volume, and if not, data stays in the container filesystem and is lost when the container exits (which you want).  I think if you do have a VOLUME then the container runtime will automatically create an anonymous volume for you; the overall behavior will be similar (it’s hard for other containers to find/use the anonymous volume) but in plain Docker at least you need to remember to clean it up.</p>
