title: Dockerfile can COPY files into a declared volume, but RUN cannot create files?
body: <p>I've been expiriencing a bit of weird behavior regarding volumes.  We have a container which contains a database, and is expected to bind mount folders from the host which contain the data.  I'm trying to create a child container which ships with test data, as it is just used for testing.  </p>
  
  <p>This requires that during the build step, some data is copied off the host machine, and then some scripts run which create additional files.  I've noticed however though when I have a look at the running container, only the copied files exist, and the ones created by scripts do not.  I've boiled down the steps to the following docker file:</p>
  
  <pre><code>FROM ubuntu:xenial-20180112.1
  
  VOLUME /test
  
  COPY /test/copydir/copyfile.txt /test/copydir/copyfile.txt
  
  RUN mkdir -p /test/mkdir &amp;&amp; \
      touch /test/mkdir/touch.txt
  </code></pre>
  
  <p>Note that when I bash into the running container and do an </p>
  
  <pre><code>ls -l /test
  </code></pre>
  
  <p>I only get the 'copydir' folder.  If I run an ls in my dockerfile however, I see that both folders exist.</p>
  
  <p>What's going on here?</p>
  
  <p>edit:</p>
  
  <p>For additional context, the following prints out that both directories exist:</p>
  
  <pre><code>FROM ubuntu:xenial-20180112.1
  
  VOLUME /test
  
  COPY /test/copydir/copyfile.txt /test/copydir/copyfile.txt
  
  RUN mkdir -p /test/mkdir &amp;&amp; \
      touch /test/mkdir/touch.txt &amp;&amp; \
      ls -l /test
  </code></pre>
  
  <p>But the following only shows that copydir exists:</p>
  
  <pre><code>FROM ubuntu:xenial-20180112.1
  
  VOLUME /test
  
  COPY /test/copydir/copyfile.txt /test/copydir/copyfile.txt
  
  RUN mkdir -p /test/mkdir &amp;&amp; \
      touch /test/mkdir/touch.txt
  
  RUN ls -l /test
  </code></pre>