title: Sharing a single file from host machine with Docker Container and having the Container r+w to same file
body: <p>I've got a situation where I've got a .json file that I want to persist between runs of a given container. In addition this file needs to be appended to by the container as part of it running.  </p>
  
  <p>The syntax which I've been using so far is as follows:</p>
  
  <pre><code>docker run -d -p 3001:3001 -v /usr/bob/database.json:/app/data/database.json:rw --name=myapp appImage  
  </code></pre>
  
  <p>Nothing gets inserted into the file (though I can cat the contents inside and outside the container to confirm it's the same).  I have ensured that the root user (yes not best practice) who is running docker owns all of the files in that folder and has full rwx.</p>
  
  <p>What DOES work is if I bind at the folder level eg:</p>
  
  <pre><code>docker run -d -p 3001:3001 -v /usr/bob:/app/data --name=myapp appImage
  </code></pre>
  
  <p>Can anyone explain the difference?  </p>
  
  <p>I feel that sharing access to a folder instead of a single file is a lot less precise and also causes structural changes in the app (eg. source control with multiple files (plus the .json file mentioned) in the same folder).</p>
  
  <p>Thanks in advance for any pointers.</p>
  
  <p>Thanks,</p>
  
  <p>Andrew</p>