title: Docker custom user id permissions in a volume (mounted and not mounted)
body: <p><strong>On the lates MacOS, with Docker for Mac Version 18.06.0-ce-mac70 (26399).</strong></p>
  
  <p>I built an <strong>example</strong> Docker image that runs as non-root with a custom user created. This is the <strong>Dockerfile</strong>:</p>
  
  <pre><code>FROM debian:jessie
  
  RUN mkdir /data &amp;&amp; \
      groupadd bar &amp;&amp; useradd -d /home/foo -g bar -m -s /bin/bash foo &amp;&amp; \
      chown foo:bar /data
  
  VOLUME /data
  
  USER foo
  
  ENTRYPOINT ["/bin/bash"]
  </code></pre>
  
  <p>I built the image. Called it <code>test:1</code> </p>
  
  <p>When I run </p>
  
  <pre><code>docker run -it test:1 -c "ls -la /data"
  </code></pre>
  
  <p>I see <code>/data</code> is properly owned by user <strong>foo:bar</strong>.</p>
  
  <p>When I run </p>
  
  <pre><code>docker run -it --user 1717:1818 test:1 -c "ls -la /data; touch /data/test"
  </code></pre>
  
  <p>I get the a permission error</p>
  
  <pre><code>total 8
  drwxr-xr-x 2 foo  bar  4096 Aug 18 18:04 .
  drwxr-xr-x 1 root root 4096 Aug 18 18:12 ..
  touch: cannot touch '/data/test': Permission denied
  </code></pre>
  
  <p>If I mount a host directory</p>
  
  <pre><code>docker run -it --user 1717:1818 -v $(pwd)/data:/data test:1 -c "touch /data/test; ls -la /data"
  </code></pre>
  
  <p>It works without an error!</p>
  
  <pre><code>total 4
  drwxr-xr-x 3 1717 1818   96 Aug 18 18:18 .
  drwxr-xr-x 1 root root 4096 Aug 18 18:20 ..
  -rw-r--r-- 1 1717 1818    0 Aug 18 18:20 test
  </code></pre>
  
  <p>Now I go into the container to debug</p>
  
  <pre><code>docker run -it --user 1717:1818 test:1
  </code></pre>
  
  <p>And I'm in a shell. Running a few tests:</p>
  
  <pre><code>I have no name!@75deaf12dcdd:/$ id
  uid=1717 gid=1818 groups=1818
  
  I have no name!@75deaf12dcdd:/$ cat /etc/passwd
  ...
  foo:x:1000:1000::/home/foo:/bin/bash
  </code></pre>
  
  <p>So.. finally to my questions.</p>
  
  <ul>
  <li>Why are the permissions of the custom user (--user 1717:1818) applied only on a mounted volume?</li>
  <li><strong>The important one:</strong> Is there a way to apply custom user uid:gid on all files and directories at container execution time (running as non-root)? </li>
  </ul>