title: When does docker copy files into a volume at runtime?
body: <p>I'm trying to understand when containers copy preexisting files into a mounted volume on the same directory. For example </p>
  
  <pre><code>FROM ubuntu
  RUN mkdir /testdir 
  RUN echo "Hello world" &gt; /testdir/file.txt
  </code></pre>
  
  <p>running:</p>
  
  <pre><code>#docker create volume vol
  #docker run -dit -v vol:/testdir myimage
  #docker exec -it 900444b7ab86 ls -la /testdir
  drwxr-xr-x 2 root root 4096 May 11 18:43 .
  drwxr-xr-x 1 root root 4096 May 11 18:43 ..
  -rw-r--r-- 1 root root    6 May 11 17:53 file.txt
  </code></pre>
  
  <p>The image for example also has files in:</p>
  
  <pre><code># docker exec -it 900444b7ab86 ls -la /etc/cron.daily
  total 20
  
      drwxr-xr-x 2 root root 4096 Apr 26 21:17 .
      drwxr-xr-x 1 root root 4096 May 11 18:43 ..
      -rwxr-xr-x 1 root root 1478 Apr 20 10:08 apt-compat
      -rwxr-xr-x 1 root root 1176 Nov  2  2017 dpkg
      -rwxr-xr-x 1 root root  249 Jan 25 15:09 passwd
  </code></pre>
  
  <p>But for example when I run it with </p>
  
  <pre><code>docker run -it 900444b7ab81 -v vol:/etc/cron.daily
  </code></pre>
  
  <p>The directory is now empty..</p>
  
  <p>Why don't the files get copied this time?</p>