<p>I tried to run a docker container that I built on a mounted network volume under Parallels.  I am adding this here to document the issue as it is different from: <a href="https://stackoverflow.com/questions/56784492/permissionerror-errno-13-permission-denied-manage-py">PermissionError: [Errno 13] Permission denied: &#39;/manage.py&#39;</a>, in that this is not an issue with /var/run/docker.sock at all but with a little known issue with the permissions on network shares and how this intersects with your container image after building.</p>
<p>Steps to reproduce the issue, this is from the Flask demo app which I was modifying to run under Kubernetes.</p>
<p>Pertinent excerpt from Dockerfile:</p>
<pre><code>WORKDIR /flaskr
COPY ./flaskr .
</code></pre>
<p>Build the image normally, then run the image with:</p>
<pre><code>docker run -p 5001:5000 flaskr-k8s:0.1.0
</code></pre>
<p>The result:</p>
<pre><code>  PermissionError

  [Errno 13] Permission denied: '/flaskr/app.py'

  at /usr/local/lib/python3.9/os.py:597 in _execvpe
       593│         argrest = (args,)
       594│         env = environ
       595│ 
       596│     if path.dirname(file):
    →  597│         exec_func(file, *argrest)
       598│         return
       599│     saved_exc = None
       600│     path_list = get_exec_path(env)
       601│     if name != 'nt':
</code></pre>

JimC
<p>The issue lies with the COPY step in the Docker manifest and how Parallels manages permissions on network shares.  Even if volumes are shared with 'ignore ownership', Parallels will make the files appear to be owned by the currently logged in user (see: <a href="http://download.parallels.com/doc/pcs/html/Parallels_Cloud_Server_Users_Guide/35697.htm" rel="nofollow noreferrer">http://download.parallels.com/doc/pcs/html/Parallels_Cloud_Server_Users_Guide/35697.htm</a>).  If you build with 'sudo', or run as a different user either when the container is launched or during the build process, then the ownership will not be correct and you will get PermissionError as above.  See: <a href="https://stackoverflow.com/questions/26500270/understanding-user-file-ownership-in-docker-how-to-avoid-changing-permissions-o">Understanding user file ownership in docker: how to avoid changing permissions of linked volumes</a> for more information on how Docker manages permissions on volumes.</p>
<p>The solution I used was to change ownership of the files after copying them to the Docker image -- in this case to user 1000 as it is the user that will be running the containers by default on my Kubernetes nodes:</p>
<pre><code># Dockerfile extract
...
COPY ./app /app/updatr

# do stuff

# fix permissions
RUN chown -R 1000:1000 /app

# lastly
USER 1000

</code></pre>
<p>There are other solutions, please see: <a href="https://blog.gougousis.net/file-permissions-the-painful-side-of-docker/" rel="nofollow noreferrer">https://blog.gougousis.net/file-permissions-the-painful-side-of-docker/</a>, <a href="https://vsupalov.com/docker-shared-permissions/" rel="nofollow noreferrer">https://vsupalov.com/docker-shared-permissions/</a> and <a href="https://stackoverflow.com/questions/24549746/switching-users-inside-docker-image-to-a-non-root-user">Switching users inside Docker image to a non-root user</a> for excellent discussions.</p>
