title: Docker - Can mount an NFS share into a container but not a sub-directory of it
body: <p>I have an NFS share with the following properties:</p>
  
  <ul>
  <li>Mounted on my host on <code>/nfs/external_disk</code></li>
  <li>Owner user is <code>test_user</code> with <code>UID 1234</code></li>
  <li>Group is <code>test_group</code> with <code>GID 2222</code></li>
  <li>Permissions is <code>750</code></li>
  </ul>
  
  <p>I have a small Dockerfile with the following content</p>
  
  <pre><code>ARG tag=lts
  from jenkins/jenkins:${tag}
  
  user root
  
  # Create a new user and new group that matches what is on the host.
  ARG username=test_user
  ARG groupname=test_group
  ARG uid=1234
  ARG gid=2222
  RUN groupadd -g ${gid} ${groupname} &amp;&amp; \
      mkdir -p /users &amp;&amp; \
      useradd -l -m -u ${uid} -g ${groupname} -s /bin/bash -d /users/${username} ${username}
  
  user ${username}
  </code></pre>
  
  <p>After building the image (named <code>custom_jenkins</code>), and when I run the following command, the container is started properly and I see the original Jenkins homer stuff now copied to the share.</p>
  
  <p><code>docker run -td --rm -v /nfs/external_disk:/var/jenkins_home custom_jenkins</code></p>
  
  <p>However if I want to mount a sub-directory of the NFS share, say <code>${NFS_SHARE}/jenkins_home</code>, then I get an error:</p>
  
  <p><code>docker run -td --rm -v /nfs/external_disk/jenkins_home:/var/jenkins_home custom_jenkins</code></p>
  
  <blockquote>
    <p>docker: Error response from daemon: error while creating mount source path '/nfs/external_disk/jenkins_home': mkdir /nfs/external_disk/jenkins_home: permission denied.</p>
  </blockquote>
  
  <p>Now even if I attempt to create the sub-directory myself before starting the container, I still get the same error. Even when I set the permissions of the sub-directory to be <code>777</code>.</p>
  
  <p>Note that I am running as <code>test_user</code> which has the same UID/GID as in the container and it actually owns the NFS share.</p>
  
  <p>I have a feeling that when docker attempts to create a sub-directory, it attempts to create it as some different user (e.g. the "docker" user) which causes it to fail while creating the folder since it has no access inside the share.</p>
  
  <p>Can anyone help? thanks in advance.</p>