title: Shared volume/file permissions/ownership (Docker)
body: <p>I'm having a slightly annoying issue while using a Docker container (I'm on Ubuntu, so no virtualization like VMWare or b2d). I've built my image, and have a running container that has one shared (mounted) directory from my host, and one shared (mounted) file from my host. Here's the <code>docker run</code> command in full:</p>
  
  <pre><code>docker run -dit \
  -p 80:80 \
  --name my-container \
  -v $(pwd)/components:/var/www/components \
  -v $(pwd)/index.php:/var/www/index.php \
  my-image
  </code></pre>
  
  <p>This works great, and both <code>/components</code> (and its contents) and the file are shared appropriately. However, when I want to make changes to either the directory (e.g. adding a new file or folder), or edit the mounted file (or any file in the directory), I'm unable to do so due to incorrect permissions. Running <code>ls- lFh</code> shows that the <code>owner</code> and <code>group</code> for the mounted items have been changed to <code>libuuid:libuuid</code>. Modifying either the file or parent directory requires root permissions, which impedes my workflow (as I'm working from Sublime Text, not Terminal, I'm presented with a popup for admin privs).</p>
  
  <p><strong>Why</strong> does this occur? <strong>How</strong> can I work around this / handle this properly? From <a href="https://docs.docker.com/userguide/dockervolumes/#mount-a-host-file-as-a-data-volume" rel="noreferrer">Managing Data Volumes: Mount a Host File as a Data Volume</a>:</p>
  
  <blockquote>
    <p>Note: Many tools used to edit files including vi and sed --in-place may result in an inode change. Since Docker v1.1.0, this will produce an error such as “sed: cannot rename ./sedKdJ9Dy: Device or resource busy”. In the case where you want to edit the mounted file, it is often easiest to instead mount the parent directory.</p>
  </blockquote>
  
  <p>This would seem to suggest that instead of mounting <code>/components</code> and <code>/index.php</code>, I should instead mount the parent directory of both. Sounds great in theory, but based on the behavior of the <code>-v</code> option and how it interacts with <code>/directory</code>, it would seem that <em>every</em> file in my parent directory would be altered to be owned by <code>libuuid:libuuid</code>. Additionally, I have lots of things inside the parent directory that are not needed in the container - things like build tools, various files, some compressed folders, etc. Mounting the whole parent directory would seem to be wasteful.</p>
  
  <p>Running <code>chown user:group</code> on <code>/components</code> and <code>/index.php</code> <em>on my host machine</em> allow me to work around this and seem to continue to sync with the container. Is this something I'll need to do every time I run a container with mounted host volumes? I'm guessing that there is a more efficient way to do this, and I'm just not finding an explanation for my particular use-case anywhere.</p>
  
  <p>I am using this container for development of a module for another program, and have no desire to manage a data-only container - the only files that matter are from my host; persistence isn't needed elsewhere (like a database, etc).</p>
  
  <ul>
  <li><a href="http://pastebin.com/uRhbxSxG" rel="noreferrer" title="Dockerfile">Dockerfile</a></li>
  <li><a href="http://pastebin.com/CBmfuVYU" rel="noreferrer" title="/setup">/setup</a></li>
  <li><em>Created on pastebin to avoid an even longer post. Never expires.</em></li>
  </ul>
  
  <p>After creating the image, this is the run command I'm using:</p>
  
  <pre><code>docker run -dit \
      -p 80:80 \
      --name my-container \
      -v $(pwd)/components:/var/www/wp-content/plugins/my-plugin-directory/components \
      -v $(pwd)/index.php:/var/www/wp-content/plugins/my-plugin-directory/index.php \
      my-image
  </code></pre>